]> granicus.if.org Git - php/commitdiff
Fixed bug #38680 (Added missing handling of basic types in json_decode).
authorIlia Alshanetsky <iliaa@php.net>
Fri, 3 Nov 2006 13:16:33 +0000 (13:16 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Fri, 3 Nov 2006 13:16:33 +0000 (13:16 +0000)
# already in HEAD

NEWS
ext/json/json.c
ext/json/tests/001.phpt
ext/json/tests/fail001.phpt

diff --git a/NEWS b/NEWS
index 8670b54f8fa2fa108cd77ae75d11e6c847f08c78..a3a81d134a96e8885581a7038eb604683310346d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2007, PHP 5.2.1
+- Fixed bug #38680 (Added missing handling of basic types in json_decode).
+  (Ilia) 
 
 02 Nov 2006, PHP 5.2.0
 - Updated bundled OpenSSL to version 0.9.8d in the Windows distro. (Edin)
index df02927d0a877633bd1af800db3ab8498bc297d3..e1943df847af16f9a60e3faf724f98dd4b82ff99 100644 (file)
@@ -451,10 +451,37 @@ static PHP_FUNCTION(json_decode)
     }
     else
     {
+       double d;
+       int type;
+       long p;
+
         zval_dtor(z);
         FREE_ZVAL(z);
         efree(utf16);
-        RETURN_NULL();
+
+       if (parameter_len == 4) {
+               if (!strcasecmp(parameter, "null")) {
+                       RETURN_NULL();
+               } else if (!strcasecmp(parameter, "true")) {
+                       RETURN_BOOL(1);
+               }
+       } else if (parameter_len == 5 && !strcasecmp(parameter, "false")) {
+               RETURN_BOOL(0);
+       }
+       if ((type = is_numeric_string(parameter, parameter_len, &p, &d, 0)) != 0) {
+               if (type == IS_LONG) {
+                       RETURN_LONG(p);
+               } else if (type == IS_DOUBLE) {
+                       RETURN_DOUBLE(d);
+               }
+       }
+       if (*parameter == '"' && parameter[parameter_len-1] == '"') {
+               RETURN_STRINGL(parameter+1, parameter_len-2, 1);
+       } else if (*parameter == '{' || *parameter == '[') { /* invalid JSON string */
+               RETURN_NULL();
+       } else {
+               RETURN_STRINGL(parameter, parameter_len, 1);
+       }
     }
 }
 
index 095aedf631965773c9d1700b363ae6b669fa40a4..4c9f918b4888786c003d041bf0e345103679bb2f 100644 (file)
@@ -31,12 +31,12 @@ NULL
 NULL
 NULL
 NULL
-NULL
-NULL
-NULL
-NULL
-NULL
-NULL
+string(1) "."
+string(1) "."
+string(3) "<?>"
+string(1) ";"
+string(12) "руссиш"
+string(4) "blah"
 NULL
 object(stdClass)#1 (1) {
   ["test"]=>
index f0e0afa387b26f96e9c8e77946961eb302cb7ba8..2f0c41b909f77c3d5e3df2e01db2a5521fec6feb 100644 (file)
@@ -45,9 +45,9 @@ foreach ($tests as $test)
 --EXPECT--
 Testing: "A JSON payload should be an object or array, not a string."
 AS OBJECT
-NULL
+string(58) "A JSON payload should be an object or array, not a string."
 AS ARRAY
-NULL
+string(58) "A JSON payload should be an object or array, not a string."
 Testing: ["Unclosed array"
 AS OBJECT
 NULL
@@ -162,4 +162,4 @@ Testing: ['single quote']
 AS OBJECT
 NULL
 AS ARRAY
-NULL
+NULL
\ No newline at end of file