php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50286 json_decode returns false when leading zeros aren't escaped with double quotes
Submitted: 2009-11-24 18:44 UTC Modified: 2009-11-24 18:48 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: ygbr at me dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.3.1 OS: Linux Debian Lenny
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ygbr at me dot com
New email:
PHP Version: OS:

 

 [2009-11-24 18:44 UTC] ygbr at me dot com
Description:
------------
When parsing a JSON Payload containing integers or floats with leading 
zeros as values which haven't been escaped using double quotes, 
json_decode() returns false.

Even thought leading zeros are ( most of the times ) irrelevant for 
integers, the function should at least trim the zeros out and not fail 
the entire decoding process. JSON returned from some Java JSON 
generators come with integers containing leading zeros and not escaped 
by double quotes.

Reproduce code:
---------------
<?php

$payload = <<<payload
{
  "test" : 06
}
payload;

if(!$obj = json_decode($payload)) die("Problems on JSON Parsing the json_decode() function has returned false");

print_r($obj);

Expected result:
----------------
stdClass Object ( [test] => 6 )

Actual result:
--------------
Problems on JSON Parsing the json_decode() function has returned false

Patches

json_parse_false_number_testing (last revision 2016-02-04 15:39 UTC by arrizaqu at yahoo dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-24 18:48 UTC] rasmus@php.net
Then those Java implementations are broken.  The JSON spec quite clearly states that if a number starts with a 0 then the only valid next character, if there is one, is a "." indicating a floating point value.  File a bug against those and point them to http://json.org

-Rasmus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 19:01:32 2024 UTC