Bug #65499 [Fbk]: json_decode reports invalid literal as valid JSON

From: Date: Thu, 22 Aug 2013 11:34:15 +0000
Subject: Bug #65499 [Fbk]: json_decode reports invalid literal as valid JSON
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-181125@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65499&edit=1 ID: 65499 Updated by: yohgaki@php.net Reported by: m dot kurzyna at crystalpoint dot pl Summary: json_decode reports invalid literal as valid JSON Status: Feedback Type: Bug Package: JSON related Operating System: Linux PHP Version: 5.5.2 Block user comment: N Private report: N New Comment: 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) Previous Comments: ------------------------------------------------------------------------ [2013-08-22 11:24:39] remi@php.net What is the return of php -r 'echo phpversion("json");' ------------------------------------------------------------------------ [2013-08-22 11:22:19] mike@php.net Cannot reproduce. Do you use Debian/Ubuntu/Fedora? Report there. ------------------------------------------------------------------------ [2013-08-22 08:15:54] 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 08:00:25] 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) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65499&edit=1

« previous php.bugs (#181125) next »