Skip to content

Commit a8fcd12

Browse files
feat: fix form url encoded strings #1593 (#1752)
1 parent 5f82841 commit a8fcd12

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Refit.Tests/RequestBuilder.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,6 +3241,29 @@ public void BodyContentGetsUrlEncoded()
32413241
Assert.Equal("Foo=Something&Bar=100&Baz=", output.SendContent);
32423242
}
32433243

3244+
[Fact]
3245+
public void BodyContentGetsUrlEncodedWithCollectionFormat()
3246+
{
3247+
var settings = new RefitSettings() { CollectionFormat = CollectionFormat.Csv };
3248+
var fixture = new RequestBuilderImplementation<IDummyHttpApi>(settings);
3249+
var factory = fixture.RunRequest("PostSomeUrlEncodedStuff");
3250+
var output = factory(
3251+
new object[]
3252+
{
3253+
6,
3254+
new
3255+
{
3256+
Foo = "Something",
3257+
Bar = 100,
3258+
FooBar = new [] {5,7},
3259+
Baz = "" // explicitly use blank to preserve value that would be stripped if null
3260+
}
3261+
}
3262+
);
3263+
3264+
Assert.Equal("Foo=Something&Bar=100&FooBar=5%2C7&Baz=", output.SendContent);
3265+
}
3266+
32443267
[Fact]
32453268
public void FormFieldGetsAliased()
32463269
{

Refit/FormValueMultimap.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public FormValueMultimap(object source, RefitSettings settings)
6565
// see if there's a query attribute
6666
var attrib = property.GetCustomAttribute<QueryAttribute>(true);
6767

68-
if (value is not IEnumerable enumerable)
68+
// add strings/non enumerable properties
69+
if (value is not IEnumerable enumerable || value is string)
6970
{
7071
Add(
7172
fieldName,

0 commit comments

Comments
 (0)