Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit e910e31

Browse files
committed
Fix serializing multiple dictionary items to Complex QueryString
1 parent d24531f commit e910e31

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/ServiceStack.Text/QueryStringSerializer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,12 @@ public static bool FormUrlEncoded(TextWriter writer, string propertyName, object
239239
var map = obj as IDictionary;
240240
if (map != null)
241241
{
242+
var i = 0;
242243
foreach (var key in map.Keys)
243244
{
245+
if (i++ > 0)
246+
writer.Write('&');
247+
244248
var value = map[key];
245249
writer.Write(propertyName);
246250
writer.Write('[');

tests/ServiceStack.Text.Tests/UseCases/StripeSerializationTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@ public void Serializes_Customer_Metadata()
6161
var dto = new CreateStripeCustomer
6262
{
6363
AccountBalance = 100,
64-
Metadata = new Dictionary<string, string> { { "order_id", "1234" } },
64+
Metadata = new Dictionary<string, string>
65+
{
66+
{ "order_id", "1234" },
67+
{ "ref_id", "456" },
68+
},
6569
};
6670

6771
var qs = QueryStringSerializer.SerializeToString(dto);
6872
qs.Print();
69-
Assert.That(qs, Is.EqualTo("account_balance=100&metadata[order_id]=1234"));
73+
Assert.That(qs, Is.EqualTo("account_balance=100&metadata[order_id]=1234&metadata[ref_id]=456"));
7074
}
7175

7276
[Test]

0 commit comments

Comments
 (0)