#41504 [Asn->Csd]: json_decode() incorrectly decodes JSON objects with empty string keys
| From: | iliaa@php.net | Date: | Sun, 27 May 2007 16:31:55 +0000 |
| Subject: | #41504 [Asn->Csd]: json_decode() incorrectly decodes JSON objects with empty string keys | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-113065@lists.php.net to get a copy of this message | ||
ID: 41504
Updated by: iliaa@php.net
Reported By: jmorrow at jessejmorrow dot com
-Status: Assigned
+Status: Closed
Bug Type: Unknown/Other Function
Operating System: OS X
PHP Version: 5.2.2
Assigned To: iliaa
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2007-05-26 20:27:05] jmorrow at jessejmorrow dot com
Awesome Iliaa - thanks for the quick reply.
Any idea when to expect the fix?
------------------------------------------------------------------------
[2007-05-26 20:20:15] iliaa@php.net
I am unable to reproduce the crash with
var_dump(json_decode('{"":"value"}', true));
it returns "_empty_" => "value" for me. Analysis through valgrind does
not report any errors either.
The issue of "" being returned as "_empty_" is a bug and will be fixed.
------------------------------------------------------------------------
[2007-05-26 07:21:23] jmorrow at jessejmorrow dot com
Description:
------------
The json_decode() function improperly and incosistently decodes JSON
objects that have an empty string as one of their object keys/property
names. In some cases the server crashes, some cases work properly, and
other cases return "_empty_" as the array key.
The "_empty_" key and crashes are show stoppers for me.
Having an empty object key/property such as {"": "value"} is totally
valid, and even common, JSON.
As a side note, I'll open a separate bug for this, json_encode(array
(""=>"value")) does not work either.
Reproduce code:
---------------
1) var_dump(json_decode('{"":"value"}', true));
2) var_dump(json_decode('{"":"value",
"key":"value"}', true));
3) var_dump(json_decode('{"key":"value",
"":"value"}', true));
Expected result:
----------------
1) array(1) { [""]=> string(5) "value" }
2) array(2) { [""]=> string(5) "value" ["key"]=> string(5)
"value" }
3) array(2) { ["key"]=> string(5) "value" [""]=> string(5)
"value" }
Actual result:
--------------
1) Page fails to return - some kind of script crash
2) array(2) { ["_empty_"]=> string(5) "value" ["key"]=>
string(5)
"value" } (the "_empty_" key coming up is the most common case when
there the key is an empty string)
3) array(2) { ["key"]=> string(5) "value" [""]=> string(5)
"value" }
(works as expected)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41504&edit=1