php.net |  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
Votes:2
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: zhaoyong dot lc at gmail dot com
New email:
PHP Version: OS:

 

 [2013-05-30 10:06 UTC] zhaoyong dot lc at gmail dot com
Description:
------------
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:
<?php
$str = "{'a':'abc'}";
var_dump(json_decode($str));

output: null

Expected result:
----------------
{"a":"abc"}

Actual result:
--------------
null

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] remi@php.net
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] remi@php.net
-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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 23:01:29 2024 UTC