Bug #70680 [Opn->Nab]: JSON_NUMERIC_CHECK does not respect the definition of numbers in RFC4627/7159
| From: | bukka@php.net | Date: | Sun, 11 Oct 2015 18:48:35 +0000 |
| Subject: | Bug #70680 [Opn->Nab]: JSON_NUMERIC_CHECK does not respect the definition of numbers in RFC4627/7159 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-196534@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70680&edit=1
ID: 70680
Updated by: bukka@php.net
Reported by: maxime dot morin at solumation dot ca
Summary: JSON_NUMERIC_CHECK does not respect the definition
of numbers in RFC4627/7159
-Status: Open
+Status: Not a bug
Type: Bug
Package: JSON related
Operating System: Debian
PHP Version: 5.4.45
-Assigned To:
+Assigned To: bukka
Block user comment: N
Private report: N
New Comment:
JSON_NUMERIC_CHECK is not about checking JSON number definition but checking whether we can convert
PHP string to number (PHP number definition rules applies here - is_numeric_string is used for
that). There is no need to limit this on JSON number definitions because encoding is done on PHP
value.
Previous Comments:
------------------------------------------------------------------------
[2015-10-09 14:48:53] maxime dot morin at solumation dot ca
Description:
------------
According to the JSON specification, a number cannot start with a 0 nor with a +.
See section 6:
"Leading zeros are not allowed."
"number = [ minus ] int [ frac ] [ exp ]"
http://www.faqs.org/rfcs/rfc7159.html
Therefore, any string starting with a 0 or a + should fail the JSON_NUMERIC_CHECK and not be cast to
an int.
Test script:
---------------
print_r(json_encode(array("shouldBeString0123456" => "0123456",
"shouldBeString+0123456" => "+0123456", "isInt" =>
"123456"), JSON_NUMERIC_CHECK));
Expected result:
----------------
{
"shouldBeString0123456":"0123456",
"shouldBeString+0123456":"+0123456",
"isInt":123456
}
Actual result:
--------------
{
"shouldBeString0123456":123456, // Bad
"shouldBeString+0123456":123456, // Bad
"isInt":123456 // Good
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70680&edit=1