]> 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)
ext/json/json.c
ext/json/tests/bug54484.phpt [new file with mode: 0644]

index db3fad9871090acc576b1739e1e70a8bfdbd04de..7231e647c3afd3af35a0ff68a555e6a30f14bc38 100644 (file)
@@ -703,6 +703,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..d698ab5
--- /dev/null
@@ -0,0 +1,25 @@
+--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)