|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64947 json_decode can't decode string with some ascii controll chars
Submitted: 2013-05-30 10:06 UTC Modified: 2013-10-15 11:54 UTC
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: zhaoyong dot lc at gmail dot com Assigned:
Status: No Feedback Package: json (PECL)
PHP Version: 5.3.25 OS: linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-05-30 10:06 UTC] zhaoyong dot lc at gmail dot com
I used json_decode to parse much more json string from fastjson library in Java,I 
found some errors which was JSON_ERROR_CTRL_CHAR or JSON_ERROR_SYNTAX always. Some 
special chars were found could cause these wrongs, so I replaced these chars to 
empty then It's work well.Code below have a control character after 'abc' which 
equals ascii 3, output of this code is Null. ascii 0 to 9 also produce wrong.

php code:
$str = "{'a':'abc'}";

output: null

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-05-30 10:10 UTC] zhaoyong dot lc at gmail dot com
$str = '{"a":"abc"}';
 [2013-06-04 13:47 UTC]
JSON_ERROR_CTRL_CHAR seems the expected behavior as control char need to be escaped.

$ php -r 'var_dump(json_decode("{\"ab\":\"abc\u0003\"}"));'
class stdClass#1 (1) {
  public $ab =>
  string(4) "abc"
 [2013-06-04 13:48 UTC]
-Status: Open +Status: Feedback
 [2013-06-05 02:13 UTC] zhaoyong dot lc at gmail dot com
Control char need to be escaped in specification of json, however, It restrict 
data exchange between java and php in json, web don't need restriction so 
strict. Meanwhile, If we can encode string that contain control chars to json in 
unicode, why we can't decode string that contains too. 

$arr = array("","","","",""); // some control chars in it 
$json = json_encode($arr);
var_dump(json_decode($json), json_encode($arr));
 [2013-10-15 11:54 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Sep 28 01:05:52 2022 UTC