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

Commit f71d083

Browse files
committed
Don't lose chars when parsing string into string[]
1 parent d4a8629 commit f71d083

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/ServiceStack.Text/Json/JsonTypeSerializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,10 @@ public bool EatItemSeperatorOrMapEndChar(ReadOnlySpan<char> value, ref int i)
712712

713713
var success = value[i] == JsWriter.ItemSeperator || value[i] == JsWriter.MapEndChar;
714714

715-
i++;
716-
717715
if (success)
718716
{
717+
i++;
718+
719719
for (; i < value.Length; i++) { var c = value[i]; if (!JsonUtils.IsWhiteSpace(c)) break; } //Whitespace inline
720720
}
721721

src/ServiceStack.Text/Jsv/JsvTypeSerializer.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,15 @@ public bool EatItemSeperatorOrMapEndChar(ReadOnlySpan<char> value, ref int i)
389389

390390
var success = value[i] == JsWriter.ItemSeperator
391391
|| value[i] == JsWriter.MapEndChar;
392-
i++;
392+
393+
if (success)
394+
{
395+
i++;
396+
}
397+
393398
return success;
394399
}
395400

396-
397401
public void EatWhitespace(string value, ref int i) {}
398402

399403
public void EatWhitespace(ReadOnlySpan<char> value, ref int i) { }
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using NUnit.Framework;
2+
3+
namespace ServiceStack.Text.Tests.Issues
4+
{
5+
public class InvalidParsingIssues
6+
{
7+
[Test]
8+
public void Parsing_string_into_string_array_splits_on_spaces()
9+
{
10+
var str = "string with a bunch of words";
11+
var result = str.FromJson<string[]>();
12+
13+
Assert.That(result, Is.EquivalentTo(str.Split(' ')));
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)