Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ protected static void RemoveQueryStringParametersThatHaveBeenUsedInTemplate(Down
{
var name = nAndV.Name.Trim(OpeningBrace, ClosingBrace);
var parameter = $"{name}={nAndV.Value}";
if (!downstreamRequest.Query.Contains(parameter))
if (!Regex.IsMatch(
downstreamRequest.Query,
$@"(?<=^|\?|&){Regex.Escape(parameter)}",
RegexOptions.IgnoreCase))
Comment thread
raman-m marked this conversation as resolved.
Outdated
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,37 @@ public async Task ShouldNotFailToHandleUrlWithSpecialRegexChars(string urlPath)
Assert.Equal((int)HttpStatusCode.OK, _httpContext.Response.StatusCode);
}

[Fact]
[Trait("Bug", "2346")]
public async Task Should_not_corrupt_query_parameter_names_containing_id_when_route_has_id_placeholder()
Comment thread
raman-m marked this conversation as resolved.
Outdated
{
var downstreamRoute = new DownstreamRouteBuilder()
.WithDownstreamPathTemplate("/v1/payment-methods")
.WithUpstreamHttpMethod(new List<string> { "Get" })
.WithDownstreamScheme("http")
.Build();
var config = new ServiceProviderConfigurationBuilder()
.Build();

GivenTheDownStreamRouteIs(new DownstreamRouteHolder(
new List<PlaceholderNameAndValue>
{
new("{id}", "123"), // This {id} placeholder should not affect customer_id query parameter
},
new Route(downstreamRoute, HttpMethod.Get)));

GivenTheDownstreamRequestUriIs("http://localhost:5003/v1/payment-methods?customer_id=12345");
GivenTheServiceProviderConfigIs(config);
GivenTheUrlReplacerWillReturn("/v1/payment-methods");

// Act
await _middleware.Invoke(_httpContext);

// Assert
ThenTheDownstreamRequestUriIs("http://localhost:5003/v1/payment-methods?customer_id=12345");
ThenTheQueryStringIs("?customer_id=12345");
}

private static ReadOnlySpan<char> GetPath(string downstreamPath)
=> DownstreamUrlCreatorMiddlewareTestWrapper.GetPath(downstreamPath);

Expand Down
Loading