Bug #67055 [NEW]: output of json_encode does not comply with the definition

From: Date: Thu, 10 Apr 2014 12:50:59 +0000
Subject: Bug #67055 [NEW]: output of json_encode does not comply with the definition
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185166@lists.php.net to get a copy of this message
From: mail+bugs dot php dot net at kazik dot de Operating system: All PHP version: Irrelevant Package: JSON related Bug Type: Bug Bug description:output of json_encode does not comply with the definition Description: ------------ The function json_encode does not encode strings accordingly to the json definition. It affects at least php since 5.3.28 up to the latest version (currently 5.5.11). According to the definition a string may not contain a quote, slash or control character. Control characters are the c0 set (0x00-0x1f), delete (0x7f) and the c1 set (0x80-0x9f) (see http://en.wikipedia.org/wiki/Unicode_control_characters). Source: ext/json/json.c, function json_escape_string The function only checks for the c0 set but does not handle delete and the c1 set correctly. The c1 set bug is only affected with the option JSON_UNESCAPED_UNICODE (since php 5.4.0). Test script: --------------- echo json_encode(chr(0x7f)).PHP_EOL; echo json_encode(chr(0xc2).chr(0x80)), JSON_UNESCAPED_UNICODE).PHP_EOL; // the utf8 representation of \u0080 Expected result: ---------------- "\u007f" "\u0080" Actual result: -------------- '"'.chr(0x7f).'"' '"'.chr(0xc2).chr(0x80).'"' // the utf8 representation of /u0080 -- Edit bug report at https://bugs.php.net/bug.php?id=67055&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67055&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67055&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67055&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=67055&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=67055&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=67055&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=67055&r=needscript Try newer version: https://bugs.php.net/fix.php?id=67055&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=67055&r=support Expected behavior: https://bugs.php.net/fix.php?id=67055&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=67055&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=67055&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=67055&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67055&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=67055&r=dst IIS Stability: https://bugs.php.net/fix.php?id=67055&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=67055&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=67055&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=67055&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=67055&r=mysqlcfg

« previous php.bugs (#185166) next »