bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSJSONSerialization: allow empty strings


From: Lubomir Rintel
Subject: NSJSONSerialization: allow empty strings
Date: Mon, 30 Jan 2012 22:01:21 +0100

* Source/NSJSONSerialization.m: (parseString): allocate string also in case
it is empty.

* Tests/base/NSJSONSerialization/json.m: (main): add a couple of test cases
for commonly seen empty content; by the way adding some whitespace
diversity.

diff --git a/Source/NSJSONSerialization.m b/Source/NSJSONSerialization.m
index cb2ac8b..6d50d9b 100644
--- a/Source/NSJSONSerialization.m
+++ b/Source/NSJSONSerialization.m
@@ -367,6 +367,10 @@ parseString(ParserState *state)
           [str release];
         }
     }
+  else if (nil == val)
+    {
+      val = [[NSMutableString alloc] init];
+    }
   if (!state->mutableStrings)
     {
       val = [val makeImmutableCopyOnFail: YES];
diff --git a/Tests/base/NSJSONSerialization/json.m 
b/Tests/base/NSJSONSerialization/json.m
index 39afa47..d7ec1fb 100644
--- a/Tests/base/NSJSONSerialization/json.m
+++ b/Tests/base/NSJSONSerialization/json.m
@@ -19,6 +19,7 @@ int main(void)
               \"Width\":  \"100\"\
           },\
       },\
+      \"emptyString\":\"\",\"emptyArray\":[],\"emptyObject\":{},\
       \"IDs\": [116, 943, 234, 38793],\
       \"escapeTest\": \"\\\"\\u0001\"\
   }";

-- 
Lubomir Rintel (GoodData)
ext.: #7715




reply via email to

[Prev in Thread] Current Thread [Next in Thread]