summaryrefslogtreecommitdiff
path: root/ext/json/json.c
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/json.c
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/json.c')
-rw-r--r--ext/json/json.c29
1 files changed, 28 insertions, 1 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);
+ }
}
}