Bug #61537 [Asn->Csd]: json_encode() incorrectly truncates/discards information
| From: | aharvey@php.net | Date: | Wed, 11 Apr 2012 00:44:38 +0000 |
| Subject: | Bug #61537 [Asn->Csd]: json_encode() incorrectly truncates/discards information | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-169419@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61537&edit=1
ID: 61537
Updated by: aharvey@php.net
Reported by: joey@php.net
Summary: json_encode() incorrectly truncates/discards
information
-Status: Assigned
+Status: Closed
Type: Bug
Package: JSON related
Operating System: all
PHP Version: 5.4.0
Assigned To: aharvey
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in SVN.
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/.
For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2012-04-11 00:44:24] aharvey@php.net
Automatic comment on behalf of adam@pwd.net.au
Revision: http://git.php.net/?p=php-src.git;a=commit;h=cb2a1c71c96d7c9b2ee03d77beae0c8e0d385f1b
Log: Fix bug #61537 (json_encode() incorrectly truncates/discards information) and remove a test
case that's now mooted by this fix.
------------------------------------------------------------------------
[2012-04-11 00:44:23] aharvey@php.net
Automatic comment on behalf of adam@pwd.net.au
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3f3ad30c50c32327e723046bcc6649d05dd9236a
Log: Fix bug #61537 (json_encode() incorrectly truncates/discards information) and remove a test
case that's now mooted by this fix.
------------------------------------------------------------------------
[2012-04-10 21:10:14] theanomaly dot is at gmail dot com
The patch submitted fixes the problem.
json_ecode() has been incorrectly documented all along. Instead of json_encode()
returning false it has been gladly returning a string containing "null" to
replace invalid data. Now, "null" is valid json, but the problem is the user
never ends up knowing that json_encode() silently failed unless they explicitly
check json_last_error() every single time they call json_encode(). Clearly this
was not the documented behavior.
It should be the case that when the user tries...
<?php
if (!(json_encode() = $json)) {
/* Then we have valid json to work with and there is no error */
} else {
/*
json_encode() failed and we should check json_last_error()
in order to know why
*/
?>
I also submitted a patch to fix the problem not realizing there was another
patch already there which fixes it too and allows it throw the error.
https://github.com/srgoogleguy/php-
src/commit/ba181fce117a3a7d1c7668cf30744b3d7cd7cdbf
However, now there is a test that's going to fail ext/json/tests/bug43941.phpt
which is testing for undocumented behavior. It was in response to this older bug
report:
https://bugs.php.net/bug.php?id=43941
However, that fix never really fixed the problem. It just made it worse. In my
opinion we should remove this test. I just wanted aharvey@php.net to also look
at in case they feel the test should remain or be modified to comply with the
spec.
Thanks.
------------------------------------------------------------------------
[2012-04-02 01:19:07] aharvey@php.net
Haven't heard any screaming, so let's go with option 2.
------------------------------------------------------------------------
[2012-03-28 08:11:39] yohgaki@php.net
I prefer option 2.
It's an error condition anyway.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=61537
--
Edit this bug report at https://bugs.php.net/bug.php?id=61537&edit=1