com php-src: json_decode() should generate a synt ax error when given "".: NEWS ext/json/json .c ext/json/tests/bug54484.phpt ext/json/test
s/bug68938.phpt
| From: | Adam Harvey | Date: | Mon, 02 Feb 2015 11:07:34 +0000 |
| Subject: | com php-src: json_decode() should generate a synt ax error when given "".: NEWS ext/json/json .c ext/json/tests/bug54484.phpt ext/json/test s/bug68938.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-84567@lists.php.net to get a copy of this message | ||
Commit: a7b3abe4e6f5e2fdfd8d55b676c9ca6b3f9c8cc8
Author: Adam Harvey <aharvey@php.net> Mon, 2 Feb 2015 11:07:34 +0000
Parents: fb803ff81993eb8acde0cdd5f513b6253221c349
Branches: PHP-5.5 PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a7b3abe4e6f5e2fdfd8d55b676c9ca6b3f9c8cc8
Log:
json_decode() should generate a syntax error when given "".
Fixes bug #68938 (json_decode() decodes empty string without error).
Patch by jeremy at bat-country dot us.
Bugs:
https://bugs.php.net/68938
Changed paths:
M NEWS
M ext/json/json.c
M ext/json/tests/bug54484.phpt
A ext/json/tests/bug68938.phpt
Diff:
diff --git a/NEWS b/NEWS
index 7a15879...bcf021f 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,10 @@ PHP NEWS
. Fixed bug #68571 (core dump when webserver close the socket).
(redfoxli069 at gmail dot com, Laruence)
+- JSON:
+ . Fixed bug #68938 (json_decode() decodes empty string without error).
+ (jeremy at bat-country dot us)
+
- Libxml:
. Fixed bug #64938 (libxml_disable_entity_loader setting is shared
between threads). (Martin Jansen)
diff --git a/ext/json/json.c b/ext/json/json.c
index 5b71eb0..27aed96 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -818,6 +818,7 @@ static PHP_FUNCTION(json_decode)
JSON_G(error_code) = 0;
if (!str_len) {
+ JSON_G(error_code) = PHP_JSON_ERROR_SYNTAX;
RETURN_NULL();
}
diff --git a/ext/json/tests/bug54484.phpt b/ext/json/tests/bug54484.phpt
index d698ab5..e56d8bd 100644
--- a/ext/json/tests/bug54484.phpt
+++ b/ext/json/tests/bug54484.phpt
@@ -15,11 +15,16 @@ json_decode("invalid json");
var_dump(json_last_error());
+json_decode("\001 invalid json");
+var_dump(json_last_error());
+
+
json_decode("");
var_dump(json_last_error());
?>
--EXPECT--
int(0)
-int(0)
int(4)
-int(0)
+int(4)
+int(3)
+int(4)
diff --git a/ext/json/tests/bug68938.phpt b/ext/json/tests/bug68938.phpt
new file mode 100644
index 0000000..f6291ff
--- /dev/null
+++ b/ext/json/tests/bug68938.phpt
@@ -0,0 +1,11 @@
+--TEST--
+Bug #68938 (json_decode() decodes empty string without indicating error)
+--SKIPIF--
+<?php if (!extension_loaded("json")) print "skip"; ?>
+--FILE--
+<?php
+json_decode("");
+var_dump(json_last_error());
+?>
+--EXPECT--
+int(4)