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

Commit c51dcea

Browse files
committed
Fix whitespace array bug
1 parent b56127f commit c51dcea

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/ServiceStack.Text/Common/DeserializeListWithElements.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static string StripList(string value)
5959
if (string.IsNullOrEmpty(value))
6060
return null;
6161

62-
value = value.TrimEnd();
62+
value = value.Trim();
6363

6464
const int startQuotePos = 1;
6565
const int endQuotePos = 2;
@@ -69,7 +69,8 @@ public static string StripList(string value)
6969

7070
var pos = 0;
7171
Serializer.EatWhitespace(ret, ref pos);
72-
return ret.Substring(pos, ret.Length - pos);
72+
var val = ret.Substring(pos, ret.Length - pos);
73+
return val;
7374
}
7475

7576
public static List<string> ParseStringList(string value)

tests/ServiceStack.Text.Tests/JsonTests/JsonArrayObjectTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,21 @@ public void Can_parse_array_with_null_objects_starting_with_null_item()
160160
Assert.Null(items[0]);
161161
Assert.NotNull(items[1]);
162162
}
163+
164+
[Test]
165+
public void Can_parse_array_with_whitespaces()
166+
{
167+
var json = "[{}, {}]";
168+
var arrayObjs = JsonArrayObjects.Parse(json);
169+
Assert.That(arrayObjs.Count, Is.EqualTo(2));
170+
171+
json = " [{}, {}]";
172+
arrayObjs = JsonArrayObjects.Parse(json);
173+
Assert.That(arrayObjs.Count, Is.EqualTo(2));
174+
175+
json = " [ { } , { } ] ";
176+
arrayObjs = JsonArrayObjects.Parse(json);
177+
Assert.That(arrayObjs.Count, Is.EqualTo(2));
178+
}
163179
}
164180
}

0 commit comments

Comments
 (0)