summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott MacVicar <scottmac@php.net>2009-02-12 00:36:23 +0000
committerScott MacVicar <scottmac@php.net>2009-02-12 00:36:23 +0000
commit921ea6a4285b6f10f68811e311792dbd3d6d9462 (patch)
tree13c511cc36f8b07dfadd4c29506e9a3a7a6d8b75
parent519e4c11587fea964116b7afcd543543e1e91b92 (diff)
downloadphp-git-921ea6a4285b6f10f68811e311792dbd3d6d9462.tar.gz
MFH Fix bug #45989 - json_decode() doesn't return NULL on certain invalid strings
-rw-r--r--ext/json/json.c6
-rw-r--r--ext/json/tests/001.phpt12
-rw-r--r--ext/json/tests/bug42090.phpt9
3 files changed, 9 insertions, 18 deletions
diff --git a/ext/json/json.c b/ext/json/json.c
index 2c6f8642d1..70d704203d 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -479,13 +479,7 @@ static PHP_FUNCTION(json_decode)
RETURN_DOUBLE(d);
}
}
- if (parameter_len > 1 && *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 e227e978eb..02d43c4243 100644
--- a/ext/json/tests/001.phpt
+++ b/ext/json/tests/001.phpt
@@ -16,7 +16,6 @@ var_dump(json_decode(";"));
var_dump(json_decode("руссиш"));
var_dump(json_decode("blah"));
var_dump(json_decode(NULL));
-var_dump(json_decode('[1}'));
var_dump(json_decode('{ "test": { "foo": "bar" } }'));
var_dump(json_decode('{ "test": { "foo": "" } }'));
var_dump(json_decode('{ "": { "foo": "" } }'));
@@ -32,12 +31,11 @@ NULL
NULL
NULL
NULL
-string(1) "."
-string(1) "."
-string(3) "<?>"
-string(1) ";"
-string(12) "руссиш"
-string(4) "blah"
+NULL
+NULL
+NULL
+NULL
+NULL
NULL
NULL
object(stdClass)#%d (1) {
diff --git a/ext/json/tests/bug42090.phpt b/ext/json/tests/bug42090.phpt
index bccd28aba0..9e5b3317e5 100644
--- a/ext/json/tests/bug42090.phpt
+++ b/ext/json/tests/bug42090.phpt
@@ -1,5 +1,5 @@
--TEST--
-Bug#42090 (json_decode causes segmentation fault)
+Bug #42090 (json_decode causes segmentation fault)
--SKIPIF--
<?php if (!extension_loaded("json")) print "skip"; ?>
--FILE--
@@ -16,10 +16,9 @@ var_dump(
?>
--EXPECT--
string(0) ""
-string(5) "".."."
-string(1) """
-string(2) """"
+NULL
+NULL
+NULL
string(4) ""\"""
string(1) """
string(2) """"
-