php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #68938
Patch json-decode-empty-string-error.diff revision 2015-01-28 21:51 UTC by jeremy at bat-country dot us

Patch json-decode-empty-string-error.diff for JSON related Bug #68938

Patch version 2015-01-28 21:51 UTC

Return to Bug #68938 | Download this patch
Patch Revisions:

Developer: jeremy@bat-country.us

diff --git a/ext/json/json.c b/ext/json/json.c
index f52215a..79e5d28 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..1ca265e 100644
--- a/ext/json/tests/bug54484.phpt
+++ b/ext/json/tests/bug54484.phpt
@@ -11,7 +11,7 @@ json_decode("");
 var_dump(json_last_error());
 
 
-json_decode("invalid json");
+json_decode("\001 invalid json");
 var_dump(json_last_error());
 
 
@@ -20,6 +20,6 @@ var_dump(json_last_error());
 ?>
 --EXPECT--
 int(0)
-int(0)
 int(4)
-int(0)
+int(3)
+int(4)
diff --git a/ext/json/tests/bugXXXXX.phpt b/ext/json/tests/bugXXXXX.phpt
new file mode 100644
index 0000000..fde856b
--- /dev/null
+++ b/ext/json/tests/bugXXXXX.phpt
@@ -0,0 +1,11 @@
+--TEST--
+Bug #XXXXX (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)
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Fri Mar 24 20:01:40 2017 UTC