From:             stas at zend dot com
Operating system: *
PHP version:      5.3CVS-2008-01-25 (CVS)
PHP Bug Type:     JSON related
Bug description:  json_encode silently cuts non-UTF8 strings

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 bug report at http://bugs.php.net/?id=43941&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=43941&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=43941&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=43941&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=43941&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=43941&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=43941&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=43941&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=43941&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=43941&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=43941&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=43941&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=43941&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=43941&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=43941&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=43941&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=43941&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=43941&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=43941&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=43941&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=43941&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=43941&r=mysqlcfg

Reply via email to