summaryrefslogtreecommitdiff
path: root/ext/json
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2006-11-03 13:16:33 +0000
committerIlia Alshanetsky <iliaa@php.net>2006-11-03 13:16:33 +0000
commit57f295d3a610074fa9863586dcda798007ee44ee (patch)
treef49fb5eaf0ab08a9dd2dc684be89d7859e557e41 /ext/json
parent7b48ca584c4ba36984bb819af82d6a74f77f4e7a (diff)
downloadphp-git-57f295d3a610074fa9863586dcda798007ee44ee.tar.gz
Fixed bug #38680 (Added missing handling of basic types in json_decode).
# already in HEAD
Diffstat (limited to 'ext/json')
-rw-r--r--ext/json/json.c29
-rw-r--r--ext/json/tests/001.phpt12
-rw-r--r--ext/json/tests/fail001.phpt6
3 files changed, 37 insertions, 10 deletions
diff --git a/ext/json/json.c b/ext/json/json.c
index df02927d0a..e1943df847 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -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);
+ }
}
}
diff --git a/ext/json/tests/001.phpt b/ext/json/tests/001.phpt
index 095aedf631..4c9f918b48 100644
--- a/ext/json/tests/001.phpt
+++ b/ext/json/tests/001.phpt
@@ -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"]=>
diff --git a/ext/json/tests/fail001.phpt b/ext/json/tests/fail001.phpt
index f0e0afa387..2f0c41b909 100644
--- a/ext/json/tests/fail001.phpt
+++ b/ext/json/tests/fail001.phpt
@@ -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