Permalink
Browse files

Fix parsing prettyPrint tab in empty list

  • Loading branch information...
1 parent af10f9c commit 6ca3b355152412b6a7c83519081a80f7fb2e8a9b @mythz mythz committed Dec 9, 2012
@@ -60,9 +60,13 @@ internal static string StripList(string value)
const int startQuotePos = 1;
const int endQuotePos = 2;
- return value[0] == JsWriter.ListStartChar
+ var ret = value[0] == JsWriter.ListStartChar
? value.Substring(startQuotePos, value.Length - endQuotePos)
: value;
+
+ var pos = 0;
+ Serializer.EatWhitespace(ret, ref pos);
+ return ret.Substring(pos, ret.Length - pos);
}
public static List<string> ParseStringList(string value)
@@ -1,7 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using System.Collections.Generic;
using NUnit.Framework;
namespace ServiceStack.Text.Tests.JsonTests
@@ -24,6 +21,12 @@ public void Can_parse_empty_array()
}
[Test]
+ public void Can_parse_empty_array_with_tab()
+ {
+ Assert.That(JsonArrayObjects.Parse("[\t]"), Is.Empty);
+ }
+
+ [Test]
public void Can_parse_array_with_null()
{
Assert.That(JsonArrayObjects.Parse("[null]"), Is.Empty);
@@ -48,5 +51,23 @@ public void Can_parse_empty_array_with_mixed_whitespaces()
{
Assert.That(JsonArrayObjects.Parse("[ \n\t \n\r]"), Is.Empty);
}
+
+ public class NamesTest
+ {
+ public NamesTest(List<string> names)
+ {
+ Names = names;
+ }
+
+ public List<string> Names { get; set; }
+ }
+
+ [Test]
+ public void Can_parse_empty_array_in_dto_with_tab()
+ {
+ var prettyJson = "{\"Names\":[\t]}";
+ var oPretty = prettyJson.FromJson<NamesTest>();
+ Assert.That(oPretty.Names.Count, Is.EqualTo(0));
+ }
}
}

0 comments on commit 6ca3b35

Please sign in to comment.