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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
46 - 38 = ?
Subscribe to this entry?

 
 [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: Tue Apr 16 17:01:30 2024 UTC