#43941 [Opn->Csd]: json_encode silently cuts non-UTF8 strings
| From: | stas@php.net | Date: | Wed, 30 Jan 2008 03:22:14 +0000 |
| Subject: | #43941 [Opn->Csd]: json_encode silently cuts non-UTF8 strings | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-121769@lists.php.net to get a copy of this message | ||
ID: 43941
Updated by: stas@php.net
Reported By: stas at zend dot com
-Status: Open
+Status: Closed
Bug Type: JSON related
Operating System: *
PHP Version: 5.3CVS-2008-01-25 (CVS)
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:
------------------------------------------------------------------------
[2008-01-25 22:19:43] stas at zend dot com
Description:
------------
Right now, if json_encode sees wrong UTF-8 data, it just cuts the
string in the middle, no error returned, no message produced.
I think it's not a good idea to just silently cut the data. In fact, I
think it is a bug caused by this code in ext/json/utf8_to_utf16.c:
if (c < 0) {
return UTF8_END ? the_index : UTF8_ERROR;
}
which inherited this bug from code published on json.org. It should
be:
if (c < 0) {
return (c == UTF8_END) ? the_index : UTF8_ERROR;
}
Reproduce code:
---------------
var_dump(json_encode("ab\xE0"));
var_dump(json_encode("ab\xE0\""));
Expected result:
----------------
Some error message
Actual result:
--------------
Just:
""ab""
""ab""
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43941&edit=1