1
0
mirror of https://github.com/php/php-src.git synced 2026-04-24 08:28:26 +02:00

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.
This commit is contained in:
Adam Harvey
2015-02-02 11:07:34 +00:00
parent fb803ff819
commit a7b3abe4e6
4 changed files with 23 additions and 2 deletions
+4
View File
@@ -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)
+1
View File
@@ -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();
}
+7 -2
View File
@@ -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)
+11
View File
@@ -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)