Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
40 changes: 40 additions & 0 deletions Refit.Tests/RequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,15 @@ Task<string> FetchSomeStuffWithHardcodedAndOtherQueryParameters(
[Get("/foo/bar?param=first {id} and second {id}")]
Task<string> FetchSomeStuffWithTheIdInAParameterMultipleTimes(int id);

[Get("/foo?q=app_metadata.id:\"{id}\"")]
Task<string> FetchSomeStuffWithDoubleQuotesInUrl(int id);

[Get("/foo/bar/({id})")]
Task<string> GetWithTrainingParenthesis(int id);

[Get("/foo/bar/{id}/")]
Task<string> GetWithTrailingSlash(int id);

[Post("/foo/bar/{id}")]
[Headers("Content-Type: literally/anything")]
Task<string> PostSomeStuffWithHardCodedContentTypeHeader(int id, [Body] string content);
Expand Down Expand Up @@ -2594,6 +2603,37 @@ public void QueryParamWithPathDelimiterShouldBeEncoded()
);
}

[Fact]
public void QueryParamWhichEndsInDoubleQuotesShouldNotBeTruncated()
{
var fixture = new RequestBuilderImplementation<IDummyHttpApi>();
var factory = fixture.BuildRequestFactoryForMethod(
"FetchSomeStuffWithDoubleQuotesInUrl"
);
var output = factory([42]);

var uri = new Uri(new Uri("http://api"), output.RequestUri!);

Assert.Equal("/foo?q=app_metadata.id%3A%2242%22", uri.PathAndQuery);
}

[Theory]
[InlineData("GetWithTrainingParenthesis", ")", "/foo/bar/(1)")]
[InlineData("GetWithTrailingSlash", "/", "/foo/bar/1/")]
public void ShouldCaptureLastCharacterWhenRouteEndsWithConstant(string methodToTest, string constantChar, string contains)
{
var fixture = new RequestBuilderImplementation<IDummyHttpApi>();
var factory = fixture.BuildRequestFactoryForMethod(
methodToTest
);
var output = factory(["1"]);

var uri = new Uri(new Uri("http://api/"), output.RequestUri!);

Assert.EndsWith(constantChar, uri.PathAndQuery, StringComparison.Ordinal);
Assert.Contains(contains, uri.PathAndQuery, StringComparison.Ordinal);
}

[Fact]
public void ParameterizedQueryParamsShouldBeInUrlAndValuesEncodedWhenMixedReplacementAndQueryBadId()
{
Expand Down
10 changes: 5 additions & 5 deletions Refit/RestMethodInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,12 @@ ParameterInfo[] parameterInfo
}
}

if (index >= relativePath.Length) return (ret, fragmentList);

// add trailing string
if (index < relativePath.Length - 1)
{
var trailingConstant = relativePath.Substring(index, relativePath.Length - index);
fragmentList.Add(ParameterFragment.Constant(trailingConstant));
}
var trailingConstant = relativePath.Substring(index);
fragmentList.Add(ParameterFragment.Constant(trailingConstant));

return (ret, fragmentList);
}

Expand Down