Skip to content

Commit

Permalink
feat: fix form url encoded strings #1593 (#1752)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMakkison committed Jul 1, 2024
1 parent 5f82841 commit a8fcd12
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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

0 comments on commit a8fcd12

Please sign in to comment.