Bug #70680 [Nab]: JSON_NUMERIC_CHECK does not respect the definition of numbers in RFC4627/7159

From: Date: Wed, 21 Oct 2015 18:00:18 +0000
Subject: Bug #70680 [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-196730@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: Not a bug Type: Bug Package: JSON related Operating System: Debian PHP Version: 5.4.45 Assigned To: bukka Block user comment: N Private report: N New Comment: No the JSON prefix is there because it's a part of the json extension which is a convention. Basically it's called NUMERIC_STRING with JSON_ prefix saying that it's a json constant. Previous Comments: ------------------------------------------------------------------------ [2015-10-13 12:36:01] maxime dot morin at solumation dot ca Shouldn't it be called PHP_NUMERIC_CHECK then? ------------------------------------------------------------------------ [2015-10-11 18:48:34] bukka@php.net 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#196730) next »