Edit report at https://bugs.php.net/bug.php?id=64695&edit=1
ID: 64695
Comment by: keith at openx dot com
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
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2013-04-23 04:15:14] keith at openx dot com
Description:
------------
So, it looks like that when you call json_encode with the JSON_NUMERIC_CHECK
option on strings that have all numbers except for one letter 'e' PHP throws a
warning:
PHP Warning: json_encode(): double INF does not conform to the JSON spec,
encoded as 0 in php shell code on line 1
It happens only on certain strings that make PHP think the number is very
large.
According to the docs the 'e' should be followed with +/-, but it seems that
isn't the case.
This causes a problem whenever converting values that are, say, hashed with
SHA1.
Since the valid characters are [0-9][A-F], it's very possible to have a value
that is: [0-9]e[0-9]
Test script:
---------------
<?php
$t = array('test' => '123343e871700');
var_dump(json_encode($t, JSON_NUMERIC_CHECK));
Expected result:
----------------
string(10) "{"test":"123343e871700"}"
Actual result:
--------------
PHP Warning: json_encode(): double INF does not conform to the JSON spec,
encoded as 0 in php shell code on line 1
string(10) "{"test":0}"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64695&edit=1