Bug #64695 [Com]: JSON_NUMERIC_CHECK has issues with strings that are numbers plus the letter e
| From: | bukka@php.net | Date: | Wed, 21 Jan 2015 20:41:46 +0000 |
| Subject: | Bug #64695 [Com]: 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-190121@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
Comment by: bukka@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: Assigned
Type: Bug
Package: JSON related
Operating System: CentOS/OSX
PHP Version: 5.3.24
Assigned To: bukka
Block user comment: N
Private report: N
New Comment:
It looks like a bug to me.
I comitted a fix to jsond: https://github.com/bukka/php-jsond/commit/37503cdff35733d580f289047f516a5df2e01813
I would like to wait after the jsond rfc vote and then possibly merge it to the core if no
objections.
Previous Comments:
------------------------------------------------------------------------
[2015-01-21 04:20:52] laruence@php.net
is this possible to be fixed in jsond?
------------------------------------------------------------------------
[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}"
------------------------------------------------------------------------
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