Skip to content

Commit 83b09f2

Browse files
committed
bug: stop removing trailing single chars from query string
Closes #2044
1 parent 49a6731 commit 83b09f2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Refit.Tests/RequestBuilder.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,9 @@ Task<string> FetchSomeStuffWithHardcodedAndOtherQueryParameters(
17701770
[Get("/foo/bar?param=first {id} and second {id}")]
17711771
Task<string> FetchSomeStuffWithTheIdInAParameterMultipleTimes(int id);
17721772

1773+
[Get("/foo?q=app_metadata.id:\"{id}\"")]
1774+
Task<string> FetchSomeStuffWithDoubleQuotesInUrl(int id);
1775+
17731776
[Post("/foo/bar/{id}")]
17741777
[Headers("Content-Type: literally/anything")]
17751778
Task<string> PostSomeStuffWithHardCodedContentTypeHeader(int id, [Body] string content);
@@ -2594,6 +2597,20 @@ public void QueryParamWithPathDelimiterShouldBeEncoded()
25942597
);
25952598
}
25962599

2600+
[Fact]
2601+
public void QueryParamWhichEndsInDoubleQuotesShouldNotBeTruncated()
2602+
{
2603+
var fixture = new RequestBuilderImplementation<IDummyHttpApi>();
2604+
var factory = fixture.BuildRequestFactoryForMethod(
2605+
"FetchSomeStuffWithDoubleQuotesInUrl"
2606+
);
2607+
var output = factory(new object[] { 42 });
2608+
2609+
var uri = new Uri(new Uri("http://api"), output.RequestUri);
2610+
2611+
Assert.Equal("/foo?q=app_metadata.id%3A%2242%22", uri.PathAndQuery);
2612+
}
2613+
25972614
[Fact]
25982615
public void ParameterizedQueryParamsShouldBeInUrlAndValuesEncodedWhenMixedReplacementAndQueryBadId()
25992616
{

Refit/RestMethodInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ ParameterInfo[] parameterInfo
402402
}
403403

404404
// add trailing string
405-
if (index < relativePath.Length - 1)
405+
if (index < relativePath.Length)
406406
{
407407
var trailingConstant = relativePath.Substring(index, relativePath.Length - index);
408408
fragmentList.Add(ParameterFragment.Constant(trailingConstant));

0 commit comments

Comments
 (0)