Bug #75986 [NEW]: JSON parser not following preposed RFC
| From: | welfordmartin at gmail dot com | Date: | Tue, 20 Feb 2018 14:00:43 +0000 |
| Subject: | Bug #75986 [NEW]: JSON parser not following preposed RFC | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-214047@lists.php.net to get a copy of this message | ||
From: welfordmartin at gmail dot com
Operating system: Ubuntu Server 16.04 & Windows 10
PHP version: 7.2.2
Package: JSON related
Bug Type: Bug
Bug description:JSON parser not following preposed RFC
Description:
------------
When using json_decode to decode a string value containing "{" or "}"
the validation fails and it does not produce an object this even happens
when both are UTF-8 encoded with "\x7B" and "\x7D" respectfully. both
cases cause a 'JSON_ERROR_SYNTAX',
While the JSON code has been manually checked against the RFC4627 and it
says standard C strings well I can't believe I have to point this one
out to you but using "{" and "}" are both ASCII chars so valid in a
string.
The JSON also parses correctly in Web Browsers both Chrome, Edge & IE
parsers.
JSON Code used:
{
"defaultModel":"Campaign",
"routes" : {
"getCampaignsForWebsite":{
"scope" : "read_campaigns",
"api":{
"method" : "GET",
"uri" : "/campaign/\x7BdisplayType\x7D/\x7Bwebsite_id:\d+\x7D"
},
"perms":{
"module" : "website",
"requirement" : "read"
}
},
"getSingleCampaign":{
"scope" : "read_campaigns",
"api":{
"method" : "GET",
"uri" : "/campaign/\x7Bcampaign_id:\d+\x7D"
},
"perms":{
"module" : "campaign",
"requirement" : "read"
}
}
}
}
Test script:
---------------
$raw = file_get_contents("test.json");
$json = json_decode($raw, true);
switch (json_last_error()) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
echo ' - Unknown error';
break;
}
Expected result:
----------------
I expect an array result when using assoc or a stdClass object when not.
Actual result:
--------------
Null and json_last_error results in JSON_ERROR_SYNTAX
--
Edit bug report at https://bugs.php.net/bug.php?id=75986&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75986&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75986&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75986&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75986&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75986&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75986&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75986&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75986&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75986&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75986&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75986&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75986&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75986&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75986&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75986&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75986&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75986&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75986&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75986&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75986&r=mysqlcfg