Bug #64695 [Opn]: JSON_NUMERIC_CHECK has issues with strings that are numbers plus the letter e

From: Date: Wed, 21 Jan 2015 04:20:53 +0000
Subject: Bug #64695 [Opn]: JSON_NUMERIC_CHECK has issues with strings that are numbers plus the letter e
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190096@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64695&edit=1 ID: 64695 Updated by: laruence@php.net Reported by: keith at openx dot com Summary: JSON_NUMERIC_CHECK has issues with strings that are numbers plus the letter e Status: Open Type: Bug Package: JSON related Operating System: CentOS/OSX PHP Version: 5.3.24 -Assigned To: +Assigned To: bukka Block user comment: N Private report: N New Comment: is this possible to be fixed in jsond? Previous Comments: ------------------------------------------------------------------------ [2015-01-21 03:51:49] anzhengchao at gmail dot com issue also appears for PHP 5.6.4 (cli) (built: Jan 8 2015 09:41:21) OSX ------------------------------------------------------------------------ [2014-10-28 02:18:58] rangi dot biddle at agfirstbop dot co dot nz issue also appears for PHP 5.5.9-1ubuntu4.4 ------------------------------------------------------------------------ [2014-04-11 14:49:06] afischoff at salesforce dot com The same is true for number with leading zeros such as valid zip codes, like: 01001 json_encode with JSON_NUMERIC_CHECK will return integer: 1001 ------------------------------------------------------------------------ [2013-04-23 06:07:40] keith at openx dot com So the new patch just updates json.c. Instead of throwing the warning and setting the value to 0, it makes the value a string. That way json_encode doesn't change a value that it possibly shouldn't. Valid exponential notation values are converted. php > $t = array('test' => '123343e871700'); php > var_dump(json_encode($t, JSON_NUMERIC_CHECK)); string(24) "{"test":"123343e871700"}" php > $t = array('test' => '123343e1'); php > var_dump(json_encode($t, JSON_NUMERIC_CHECK)); string(16) "{"test":1233430}" php > $t = array('test' => '1.03e-3'); php > var_dump(json_encode($t, JSON_NUMERIC_CHECK)); string(16) "{"test":0.00103}" ------------------------------------------------------------------------ [2013-04-23 04:28:20] keith at openx dot com So, I noticed on the is_numeric page that: "Thus +0123.45e6 is a valid numeric value." But can that be explained as to why that this? It breaks json_encode when JSON_NUMERIC_CHECK is called in certain situations. The function 'is_numeric_string' returns the type 'double' for strings like "3e122345", and that isn't a double. My patch updated 'is_numeric_string' which might be too agressive. Maybe updating json.c is a better alternative. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=64695 -- Edit this bug report at https://bugs.php.net/bug.php?id=64695&edit=1

« previous php.bugs (#190096) next »