Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix form url encoded strings #1593 #1752

Merged
merged 1 commit into from
Jul 1, 2024
Merged
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
23 changes: 23 additions & 0 deletions Refit.Tests/RequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3241,6 +3241,29 @@ public void BodyContentGetsUrlEncoded()
Assert.Equal("Foo=Something&Bar=100&Baz=", output.SendContent);
}

[Fact]
public void BodyContentGetsUrlEncodedWithCollectionFormat()
{
var settings = new RefitSettings() { CollectionFormat = CollectionFormat.Csv };
var fixture = new RequestBuilderImplementation<IDummyHttpApi>(settings);
var factory = fixture.RunRequest("PostSomeUrlEncodedStuff");
var output = factory(
new object[]
{
6,
new
{
Foo = "Something",
Bar = 100,
FooBar = new [] {5,7},
Baz = "" // explicitly use blank to preserve value that would be stripped if null
}
}
);

Assert.Equal("Foo=Something&Bar=100&FooBar=5%2C7&Baz=", output.SendContent);
}

[Fact]
public void FormFieldGetsAliased()
{
Expand Down
3 changes: 2 additions & 1 deletion Refit/FormValueMultimap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public FormValueMultimap(object source, RefitSettings settings)
// see if there's a query attribute
var attrib = property.GetCustomAttribute<QueryAttribute>(true);

if (value is not IEnumerable enumerable)
// add strings/non enumerable properties
if (value is not IEnumerable enumerable || value is string)
{
Add(
fieldName,
Expand Down
Loading