Bug #70680 [NEW]: JSON_NUMERIC_CHECK does not respect the definition of numbers in RFC4627/7159
From: maxime dot morin at solumation dot ca
Operating system: Debian
PHP version: 5.4.45
Package: JSON related
Bug Type: Bug
Bug description:JSON_NUMERIC_CHECK does not respect the definition of numbers in RFC4627/7159
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 bug report at https://bugs.php.net/bug.php?id=70680&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70680&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70680&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70680&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70680&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70680&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70680&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70680&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70680&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70680&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70680&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70680&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70680&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70680&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70680&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70680&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70680&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70680&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70680&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70680&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70680&r=mysqlcfg
Thread (4 messages)
- maxime dot morin at solumation dot ca