Allow trailing commas on Json objects
authorMiguel de Icaza <miguel@gnome.org>
Thu, 29 Dec 2011 14:10:14 +0000 (09:10 -0500)
committerMiguel de Icaza <miguel@gnome.org>
Thu, 29 Dec 2011 14:10:26 +0000 (09:10 -0500)
mcs/class/System.Json/System.Json_test.dll.sources [new file with mode: 0644]
mcs/class/System.Json/Test/System.Json/JsonValueTest.cs [new file with mode: 0644]
mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JavaScriptReader.cs

diff --git a/mcs/class/System.Json/System.Json_test.dll.sources b/mcs/class/System.Json/System.Json_test.dll.sources
new file mode 100644 (file)
index 0000000..8d6ae22
--- /dev/null
@@ -0,0 +1 @@
+System.Json/JsonValueTest.cs
\ No newline at end of file
diff --git a/mcs/class/System.Json/Test/System.Json/JsonValueTest.cs b/mcs/class/System.Json/Test/System.Json/JsonValueTest.cs
new file mode 100644 (file)
index 0000000..754f855
--- /dev/null
@@ -0,0 +1,29 @@
+//
+// JsonValueTest.cs: Tests for JSonValue
+//
+// Copyright 2011 Xamarin, Inc.
+//
+// Authors:
+//   Miguel de Icaza
+//
+using NUnit.Framework;
+using System;
+using System.IO;
+using System.Text;
+using System.Json;
+
+namespace MonoTests.System
+{
+       [TestFixture]
+       public class JsonValueTests {
+               // Tests that a trailing comma is allowed in dictionary definitions
+               [Test]
+               public void LoadWithTrailingComma ()
+               {
+                       var j = JsonValue.Load (new StringReader ("{ \"a\": \"b\",}"));
+                       Assert.AreEqual (1, j.Count, "itemcount");
+                       Assert.AreEqual (JsonType.String, j ["a"].JsonType, "type");
+                       Assert.AreEqual ("b", (string) j ["a"], "value");
+               }
+       }
+}
index 0a2de0c8d9adbf31951d35d59f86e812047ece3e..84016a990286411cda232dce09c75a5522291716 100644 (file)
@@ -68,6 +68,8 @@ namespace System.Runtime.Serialization.Json
                                }
                                while (true) {
                                        SkipSpaces ();
+                                       if (PeekChar () == '}')
+                                               break;
                                        string name = ReadStringLiteral ();
                                        SkipSpaces ();
                                        Expect (':');