]> granicus.if.org Git - php/commitdiff
Fixed bug #54484 (Empty string in json_decode doesn't reset json_last_error()).
authorIlia Alshanetsky <iliaa@php.net>
Wed, 1 Jun 2011 09:44:38 +0000 (09:44 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 1 Jun 2011 09:44:38 +0000 (09:44 +0000)
NEWS
ext/json/json.c
ext/json/tests/bug54484.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index f7f9d4b3b5acc115d088a28434f5a3d600406136..29d6bd95bcc0acf6e79e50b82d6868837528e08f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -91,6 +91,10 @@ PHP                                                                        NEWS
   . Implemented FR #54540 (Allow loading of arbitrary resource bundles when
     fallback is disabled). (David Zuelke, Stas)
 
+- json extension:
+  . Fixed bug #54484 (Empty string in json_decode doesn't reset 
+    json_last_error()). (Ilia)
+
 - LDAP extension:
   . Fixed bug #53339 (Fails to build when compilng with gcc 4.5 and DSO
     libraries). (Clint Byrum, Raphael)
index ec76c1d5f38f4e40788ccc4aea69470e240a3756..5d3e44198059613bf9cace911a86b0e9de4e6ab8 100644 (file)
@@ -589,6 +589,8 @@ static PHP_FUNCTION(json_decode)
                return;
        }
 
+       JSON_G(error_code) = 0;
+
        if (!str_len) {
                RETURN_NULL();
        }
diff --git a/ext/json/tests/bug54484.phpt b/ext/json/tests/bug54484.phpt
new file mode 100644 (file)
index 0000000..a8f3108
--- /dev/null
@@ -0,0 +1,50 @@
+--TEST--
+Bug #54484 (Empty string in json_decode doesn't reset json_last_error)
+--SKIPIF--
+<?php if (!extension_loaded("json")) print "skip"; ?>
+--FILE--
+<?php
+json_decode('{"test":"test"}');
+var_dump(json_last_error());
+
+json_decode("");
+var_dump(json_last_error());
+
+
+json_decode("invalid json");
+var_dump(json_last_error());
+
+
+json_decode("");
+var_dump(json_last_error());
+?>
+--EXPECT--
+int(0)
+int(0)
+int(4)
+int(0)
+--TEST--
+Bug #54484 (Empty string in json_decode doesn't reset json_last_error)
+--SKIPIF--
+<?php if (!extension_loaded("json")) print "skip"; ?>
+--FILE--
+<?php
+json_decode('{"test":"test"}');
+var_dump(json_last_error());
+
+json_decode("");
+var_dump(json_last_error());
+
+
+json_decode("invalid json");
+var_dump(json_last_error());
+
+
+json_decode("");
+var_dump(json_last_error());
+?>
+--EXPECT--
+int(0)
+int(0)
+int(4)
+int(0)