Index: ext/json/json.c =================================================================== RCS file: /repository/php-src/ext/json/json.c,v retrieving revision 1.42 diff -u -r1.42 json.c --- ext/json/json.c 17 Nov 2008 11:26:21 -0000 1.42 +++ ext/json/json.c 3 Dec 2008 22:10:40 -0000 @@ -520,6 +520,7 @@ } else if (str_type == IS_STRING) { + /* The JSON parser failed, let's try to parse some common PHP types from STRING */ double d; int type; long p; @@ -544,16 +545,12 @@ 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); - } + /* Parsing failed, let's return NULL */ + RETURN_NULL(); } else { + /* The JSON parser failed, let's try to parse some common PHP types from UNICODE */ double d; int type; long p; @@ -577,13 +574,8 @@ 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); - } + /* Parsing failed, let's return NULL */ + RETURN_NULL(); } } /* }}} */ Index: ext/json/tests/001.phpt =================================================================== RCS file: /repository/php-src/ext/json/tests/001.phpt,v retrieving revision 1.5 diff -u -r1.5 001.phpt --- ext/json/tests/001.phpt 27 May 2008 18:16:03 -0000 1.5 +++ ext/json/tests/001.phpt 3 Dec 2008 22:10:40 -0000 @@ -31,12 +31,12 @@ 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 @@ unicode(0) "" } } -unicode(16) "{ "": { "": "" }" -unicode(16) "{ "": "": "" } }" +NULL +NULL Done Index: ext/json/tests/bug41504.phpt =================================================================== RCS file: /repository/php-src/ext/json/tests/bug41504.phpt,v retrieving revision 1.2 diff -u -r1.2 bug41504.phpt --- ext/json/tests/bug41504.phpt 22 Jul 2008 14:14:31 -0000 1.2 +++ ext/json/tests/bug41504.phpt 3 Dec 2008 22:10:40 -0000 @@ -13,19 +13,19 @@ ?> --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: ext/json/tests/bug42090.phpt =================================================================== RCS file: /repository/php-src/ext/json/tests/bug42090.phpt,v retrieving revision 1.3 diff -u -r1.3 bug42090.phpt --- ext/json/tests/bug42090.phpt 27 May 2008 18:16:03 -0000 1.3 +++ ext/json/tests/bug42090.phpt 3 Dec 2008 22:10:40 -0000 @@ -16,10 +16,9 @@ ?> --EXPECT-- unicode(0) "" -unicode(5) "".."." -unicode(1) """ -unicode(2) """" +NULL +NULL +NULL string(4) ""\""" unicode(1) """ unicode(2) """" - Index: ext/json/tests/fail001.phpt =================================================================== RCS file: /repository/php-src/ext/json/tests/fail001.phpt,v retrieving revision 1.7 diff -u -r1.7 fail001.phpt --- ext/json/tests/fail001.phpt 31 Jul 2008 11:49:19 -0000 1.7 +++ ext/json/tests/fail001.phpt 3 Dec 2008 22:10:40 -0000 @@ -50,116 +50,116 @@ 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