iliaa Wed, 01 Jun 2011 09:44:38 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=311708
Log: Fixed bug #54484 (Empty string in json_decode doesn't reset json_last_error()). Bug: http://bugs.php.net/54484 (Assigned) Empty string in json_decode doesn't set/reset json_last_error Changed paths: U php/php-src/branches/PHP_5_3/NEWS U php/php-src/branches/PHP_5_3/ext/json/json.c A php/php-src/branches/PHP_5_3/ext/json/tests/bug54484.phpt U php/php-src/branches/PHP_5_4/ext/json/json.c A php/php-src/branches/PHP_5_4/ext/json/tests/bug54484.phpt U php/php-src/trunk/ext/json/json.c A php/php-src/trunk/ext/json/tests/bug54484.phpt Modified: php/php-src/branches/PHP_5_3/NEWS =================================================================== --- php/php-src/branches/PHP_5_3/NEWS 2011-06-01 09:22:05 UTC (rev 311707) +++ php/php-src/branches/PHP_5_3/NEWS 2011-06-01 09:44:38 UTC (rev 311708) @@ -91,6 +91,10 @@ . 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) Modified: php/php-src/branches/PHP_5_3/ext/json/json.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/json/json.c 2011-06-01 09:22:05 UTC (rev 311707) +++ php/php-src/branches/PHP_5_3/ext/json/json.c 2011-06-01 09:44:38 UTC (rev 311708) @@ -589,6 +589,8 @@ return; } + JSON_G(error_code) = 0; + if (!str_len) { RETURN_NULL(); } Added: php/php-src/branches/PHP_5_3/ext/json/tests/bug54484.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/json/tests/bug54484.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/ext/json/tests/bug54484.phpt 2011-06-01 09:44:38 UTC (rev 311708) @@ -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) Modified: php/php-src/branches/PHP_5_4/ext/json/json.c =================================================================== --- php/php-src/branches/PHP_5_4/ext/json/json.c 2011-06-01 09:22:05 UTC (rev 311707) +++ php/php-src/branches/PHP_5_4/ext/json/json.c 2011-06-01 09:44:38 UTC (rev 311708) @@ -703,6 +703,8 @@ return; } + JSON_G(error_code) = 0; + if (!str_len) { RETURN_NULL(); } Added: php/php-src/branches/PHP_5_4/ext/json/tests/bug54484.phpt =================================================================== --- php/php-src/branches/PHP_5_4/ext/json/tests/bug54484.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/ext/json/tests/bug54484.phpt 2011-06-01 09:44:38 UTC (rev 311708) @@ -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) Modified: php/php-src/trunk/ext/json/json.c =================================================================== --- php/php-src/trunk/ext/json/json.c 2011-06-01 09:22:05 UTC (rev 311707) +++ php/php-src/trunk/ext/json/json.c 2011-06-01 09:44:38 UTC (rev 311708) @@ -703,6 +703,8 @@ return; } + JSON_G(error_code) = 0; + if (!str_len) { RETURN_NULL(); } Added: php/php-src/trunk/ext/json/tests/bug54484.phpt =================================================================== --- php/php-src/trunk/ext/json/tests/bug54484.phpt (rev 0) +++ php/php-src/trunk/ext/json/tests/bug54484.phpt 2011-06-01 09:44:38 UTC (rev 311708) @@ -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)
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php