php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65499 json_decode reports invalid literal as valid JSON
Submitted: 2013-08-22 08:00 UTC Modified: 2013-08-27 09:52 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: m dot kurzyna at crystalpoint dot pl Assigned:
Status: Closed Package: JSON related
PHP Version: 5.5.2 OS: Linux
Private report: No CVE-ID: None
 [2013-08-22 08:00 UTC] m dot kurzyna at crystalpoint dot pl
Description:
------------
There is a regression in json_decode starting with PHP5.5 (5.4.x works as expected). 

json_decode() now treats literals staring with an integer as valid JSON consisting only of the first character.


Test script:
---------------
<?php
var_dump(
  json_decode("9af5"), 
  json_last_error()
);

Expected result:
----------------
NULL
int(4)

Actual result:
--------------
int(9)
int(0)

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-22 08:15 UTC] m dot kurzyna at crystalpoint dot pl
To be more precise - introduced regression casts the string to integer so technically it takes all first digits just like (int)"123abc" would do.
 [2013-08-22 11:22 UTC] mike@php.net
-Status: Open +Status: Feedback
 [2013-08-22 11:22 UTC] mike@php.net
Cannot reproduce. Do you use Debian/Ubuntu/Fedora? Report there.
 [2013-08-22 11:24 UTC] remi@php.net
What is the return of php -r 'echo phpversion("json");'
 [2013-08-22 11:34 UTC] yohgaki@php.net
It seems my fedora 19 x86_64 does this, while my PHP-5.5 branch don't on the 
same machine. It seems packager's issue.

$ php
<?php
var_dump(
  json_decode("9af5"),
  json_last_error()
);



int(9)
int(0)


[yohgaki@dev PHP-5.5]$ ./php-bin 
<?php
var_dump(
  json_decode("9af5"),
  json_last_error()
);



NULL
int(4)
 [2013-08-22 15:16 UTC] m dot kurzyna at crystalpoint dot pl
-Status: Feedback +Status: Closed
 [2013-08-22 15:16 UTC] m dot kurzyna at crystalpoint dot pl
I'm at Ubuntu. 

I've built current master (from git) and also didn't reproduce this behaviour so just as you suggest - it seems to be packagers problem. 

I will report to Ubuntu maintainers.
 [2013-08-23 05:39 UTC] remi@php.net
As Fedora, Ubuntu and some other Linux distributions have switch to JSONC extension, you can report this strictness change in https://github.com/remicollet/pecl-json-c/issues?state=open
 [2013-08-23 07:10 UTC] m dot kurzyna at crystalpoint dot pl
Thanks - I've reported the issue accordingly: 
https://github.com/remicollet/pecl-json-c/issues/5
 [2013-08-27 09:52 UTC] m dot kurzyna at crystalpoint dot pl
Just to follow up - it has been fixed upstream (both in pecl-json-c and main json-c). Hopefully next distro packages will reflect this changes.

Thanks all.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC