scottmac Fri Dec 12 23:17:44 2008 UTC
Modified files:
/php-src/ext/json json.c
/php-src/ext/json/tests 001.phpt bug41504.phpt bug42090.phpt
fail001.phpt
Log:
Fix bug #45989 - json_decode() doesn't return NULL on certain invalid strings
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.42&r2=1.43&diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.42 php-src/ext/json/json.c:1.43
--- php-src/ext/json/json.c:1.42 Mon Nov 17 11:26:21 2008
+++ php-src/ext/json/json.c Fri Dec 12 23:17:44 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: json.c,v 1.42 2008/11/17 11:26:21 felipe Exp $ */
+/* $Id: json.c,v 1.43 2008/12/12 23:17:44 scottmac Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -544,13 +544,7 @@
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 @@
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();
}
}
/* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/001.phpt?r1=1.5&r2=1.6&diff_format=u
Index: php-src/ext/json/tests/001.phpt
diff -u php-src/ext/json/tests/001.phpt:1.5 php-src/ext/json/tests/001.phpt:1.6
--- php-src/ext/json/tests/001.phpt:1.5 Tue May 27 18:16:03 2008
+++ php-src/ext/json/tests/001.phpt Fri Dec 12 23:17:44 2008
@@ -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
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/bug41504.phpt?r1=1.2&r2=1.3&diff_format=u
Index: php-src/ext/json/tests/bug41504.phpt
diff -u php-src/ext/json/tests/bug41504.phpt:1.2
php-src/ext/json/tests/bug41504.phpt:1.3
--- php-src/ext/json/tests/bug41504.phpt:1.2 Tue Jul 22 14:14:31 2008
+++ php-src/ext/json/tests/bug41504.phpt Fri Dec 12 23:17:44 2008
@@ -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
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/bug42090.phpt?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/json/tests/bug42090.phpt
diff -u php-src/ext/json/tests/bug42090.phpt:1.3
php-src/ext/json/tests/bug42090.phpt:1.4
--- php-src/ext/json/tests/bug42090.phpt:1.3 Tue May 27 18:16:03 2008
+++ php-src/ext/json/tests/bug42090.phpt Fri Dec 12 23:17:44 2008
@@ -16,10 +16,9 @@
?>
--EXPECT--
unicode(0) ""
-unicode(5) "".."."
-unicode(1) """
-unicode(2) """"
+NULL
+NULL
+NULL
string(4) ""\"""
unicode(1) """
unicode(2) """"
-
http://cvs.php.net/viewvc.cgi/php-src/ext/json/tests/fail001.phpt?r1=1.7&r2=1.8&diff_format=u
Index: php-src/ext/json/tests/fail001.phpt
diff -u php-src/ext/json/tests/fail001.phpt:1.7
php-src/ext/json/tests/fail001.phpt:1.8
--- php-src/ext/json/tests/fail001.phpt:1.7 Thu Jul 31 11:49:19 2008
+++ php-src/ext/json/tests/fail001.phpt Fri Dec 12 23:17:44 2008
@@ -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:
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[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[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["Too
deep"]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]!
]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
+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
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php