]> granicus.if.org Git - php/commitdiff
Fix bug #45989 - json_decode() doesn't return NULL on certain invalid strings
authorScott MacVicar <scottmac@php.net>
Fri, 12 Dec 2008 23:17:44 +0000 (23:17 +0000)
committerScott MacVicar <scottmac@php.net>
Fri, 12 Dec 2008 23:17:44 +0000 (23:17 +0000)
ext/json/json.c
ext/json/tests/001.phpt
ext/json/tests/bug41504.phpt
ext/json/tests/bug42090.phpt
ext/json/tests/fail001.phpt

index 6f5193019e1c9fbc371901b1e540a35417cc7ab9..d00d5bb2549920352ed4f09e79c7ece9fb5167f7 100644 (file)
@@ -544,13 +544,7 @@ static PHP_FUNCTION(json_decode)
                                RETURN_DOUBLE(d);
                        }
                }
-               if (str_len > 1 && *str.s == '"' && str.s[str_len-1] == '"') {
-                       RETURN_STRINGL(str.s+1, str_len-2, 1);
-               } else if (*str.s == '{' || *str.s == '[') { /* invalid JSON string */
-                       RETURN_NULL();
-               } else {
-                       RETURN_STRINGL(str.s, str_len, 1);
-               }
+               RETURN_NULL();
        }
        else
        {
@@ -577,13 +571,7 @@ static PHP_FUNCTION(json_decode)
                                RETURN_DOUBLE(d);
                        }
                }
-               if (str_len > 1 && *str.u == 0x22 /*'"'*/ && str.u[str_len-1] == 0x22 /*'"'*/) {
-                       RETURN_UNICODEL(str.u+1, str_len-2, 1);
-               } else if (*str.u == 0x7b /*'{'*/ || *str.u == 0x5b /*'['*/ ) { /* invalid JSON string */
-                       RETURN_NULL();
-               } else {
-                       RETURN_UNICODEL(str.u, str_len, 1);
-               }
+               RETURN_NULL();
        }
 }
 /* }}} */
index a106e89f852cbdbf3d0e34614a4c805c2b929fc4..3aec70f527257b8236cefd56fd861553ac5339df 100644 (file)
@@ -31,12 +31,12 @@ NULL
 NULL
 NULL
 NULL
-unicode(1) "."
-unicode(1) "."
-unicode(3) "<?>"
-unicode(1) ";"
-unicode(6) "руссиш"
-unicode(4) "blah"
+NULL
+NULL
+NULL
+NULL
+NULL
+NULL
 NULL
 object(stdClass)#%d (1) {
   [u"test"]=>
@@ -66,6 +66,6 @@ object(stdClass)#%d (1) {
     unicode(0) ""
   }
 }
-unicode(16) "{ "": { "": "" }"
-unicode(16) "{ "": "": "" } }"
+NULL
+NULL
 Done
index bef497404f2d6be86ca3abb19cd60878328414bd..b1ff543ec7e2dae42e3faf76ff2f6de51437724d 100644 (file)
@@ -13,19 +13,19 @@ echo "Done\n";
 ?>
 --EXPECT--     
 array(1) {
-  [""]=>
-  string(5) "value"
+  [u""]=>
+  unicode(5) "value"
 }
 array(2) {
-  [""]=>
-  string(5) "value"
-  ["key"]=>
-  string(5) "value"
+  [u""]=>
+  unicode(5) "value"
+  [u"key"]=>
+  unicode(5) "value"
 }
 array(2) {
-  ["key"]=>
-  string(5) "value"
-  [""]=>
-  string(5) "value"
+  [u"key"]=>
+  unicode(5) "value"
+  [u""]=>
+  unicode(5) "value"
 }
 Done
index f8f370c8341561255b7bb03b2f64d5cd555e04c8..2b24b30d41efc6d04e4839226507a3a1f4dcff3e 100644 (file)
@@ -16,10 +16,9 @@ var_dump(
 ?>
 --EXPECT--
 unicode(0) ""
-unicode(5) "".."."
-unicode(1) """
-unicode(2) """"
+NULL
+NULL
+NULL
 string(4) ""\"""
 unicode(1) """
 unicode(2) """"
-
index 7b255b18e59491f7b6bd5f2fa56a152c0fd91343..44fc64ed294e6424d76c7c7dbb086fac2b03b182 100644 (file)
@@ -50,116 +50,116 @@ AS ARRAY
 unicode(58) "A JSON payload should be an object or array, not a string."
 Testing: ["Unclosed array"
 AS OBJECT
-unicode(17) "["Unclosed array""
+NULL
 AS ARRAY
-unicode(17) "["Unclosed array""
+NULL
 Testing: {unquoted_key: "keys must be quoted}
 AS OBJECT
-unicode(36) "{unquoted_key: "keys must be quoted}"
+NULL
 AS ARRAY
-unicode(36) "{unquoted_key: "keys must be quoted}"
+NULL
 Testing: ["extra comma",]
 AS OBJECT
-unicode(16) "["extra comma",]"
+NULL
 AS ARRAY
-unicode(16) "["extra comma",]"
+NULL
 Testing: ["double extra comma",,]
 AS OBJECT
-unicode(24) "["double extra comma",,]"
+NULL
 AS ARRAY
-unicode(24) "["double extra comma",,]"
+NULL
 Testing: [   , "<-- missing value"]
 AS OBJECT
-unicode(26) "[   , "<-- missing value"]"
+NULL
 AS ARRAY
-unicode(26) "[   , "<-- missing value"]"
+NULL
 Testing: ["Comma after the close"],
 AS OBJECT
-unicode(26) "["Comma after the close"],"
+NULL
 AS ARRAY
-unicode(26) "["Comma after the close"],"
+NULL
 Testing: ["Extra close"]]
 AS OBJECT
-unicode(16) "["Extra close"]]"
+NULL
 AS ARRAY
-unicode(16) "["Extra close"]]"
+NULL
 Testing: {"Extra comma": true,}
 AS OBJECT
-unicode(22) "{"Extra comma": true,}"
+NULL
 AS ARRAY
-unicode(22) "{"Extra comma": true,}"
+NULL
 Testing: {"Extra value after close": true} "misplaced quoted value"
 AS OBJECT
-unicode(58) "{"Extra value after close": true} "misplaced quoted value""
+NULL
 AS ARRAY
-unicode(58) "{"Extra value after close": true} "misplaced quoted value""
+NULL
 Testing: {"Illegal expression": 1 + 2}
 AS OBJECT
-unicode(29) "{"Illegal expression": 1 + 2}"
+NULL
 AS ARRAY
-unicode(29) "{"Illegal expression": 1 + 2}"
+NULL
 Testing: {"Illegal invocation": alert()}
 AS OBJECT
-unicode(31) "{"Illegal invocation": alert()}"
+NULL
 AS ARRAY
-unicode(31) "{"Illegal invocation": alert()}"
+NULL
 Testing: {"Numbers cannot have leading zeroes": 013}
 AS OBJECT
-unicode(43) "{"Numbers cannot have leading zeroes": 013}"
+NULL
 AS ARRAY
-unicode(43) "{"Numbers cannot have leading zeroes": 013}"
+NULL
 Testing: {"Numbers cannot be hex": 0x14}
 AS OBJECT
-unicode(31) "{"Numbers cannot be hex": 0x14}"
+NULL
 AS ARRAY
-unicode(31) "{"Numbers cannot be hex": 0x14}"
+NULL
 Testing: ["Illegal backslash escape: \x15"]
 AS OBJECT
-unicode(34) "["Illegal backslash escape: \x15"]"
+NULL
 AS ARRAY
-unicode(34) "["Illegal backslash escape: \x15"]"
+NULL
 Testing: ["Illegal backslash escape: \'"]
 AS OBJECT
-unicode(32) "["Illegal backslash escape: \'"]"
+NULL
 AS ARRAY
-unicode(32) "["Illegal backslash escape: \'"]"
+NULL
 Testing: ["Illegal backslash escape: \017"]
 AS OBJECT
-unicode(34) "["Illegal backslash escape: \017"]"
+NULL
 AS ARRAY
-unicode(34) "["Illegal backslash escape: \017"]"
+NULL
 Testing: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]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]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
+NULL
 Testing: {"Missing colon" null}
 AS OBJECT
-unicode(22) "{"Missing colon" null}"
+NULL
 AS ARRAY
-unicode(22) "{"Missing colon" null}"
+NULL
 Testing: {"Double colon":: null}
 AS OBJECT
-unicode(23) "{"Double colon":: null}"
+NULL
 AS ARRAY
-unicode(23) "{"Double colon":: null}"
+NULL
 Testing: {"Comma instead of colon", null}
 AS OBJECT
-unicode(32) "{"Comma instead of colon", null}"
+NULL
 AS ARRAY
-unicode(32) "{"Comma instead of colon", null}"
+NULL
 Testing: ["Colon instead of comma": false]
 AS OBJECT
-unicode(33) "["Colon instead of comma": false]"
+NULL
 AS ARRAY
-unicode(33) "["Colon instead of comma": false]"
+NULL
 Testing: ["Bad value", truth]
 AS OBJECT
-unicode(20) "["Bad value", truth]"
+NULL
 AS ARRAY
-unicode(20) "["Bad value", truth]"
+NULL
 Testing: ['single quote']
 AS OBJECT
-unicode(16) "['single quote']"
+NULL
 AS ARRAY
-unicode(16) "['single quote']"
+NULL