diff --git a/NEWS b/NEWS index 5229ff4c292f8..6132db553f472 100644 --- a/NEWS +++ b/NEWS @@ -2,4 +2,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 20??, PHP 5.7.0 +- JSON: + . Fixed bug #64874 ("json_decode handles whitespace and case-sensitivity + incorrectly") + <<< NOTE: Insert NEWS from last stable release here prior to actual release! >>> diff --git a/UPGRADING b/UPGRADING index e0861880b9ca7..56a59c1ace10b 100755 --- a/UPGRADING +++ b/UPGRADING @@ -21,6 +21,14 @@ PHP X.Y UPGRADE NOTES ======================================== +- JSON: + Fixed bug #64874 ("json_decode handles whitespace and case-sensitivity + incorrectly") + This means that when a non-lowercase JSON text containing only JSON true, + false or null is passed to json_decode(), it will error. Please note however + that non-lowercase true, false or null have never been accepted inside JSON + arrays or JSON strings. This only applies to deserialising single values. + ======================================== 2. New Features ======================================== diff --git a/ext/json/json.c b/ext/json/json.c index 5517da601d5ff..d017753de6fbc 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -712,14 +712,14 @@ PHP_JSON_API void php_json_decode_ex(zval *return_value, char *str, int str_len, RETVAL_NULL(); if (trim_len == 4) { - if (!strncasecmp(trim, "null", trim_len)) { + if (!strncmp(trim, "null", trim_len)) { /* We need to explicitly clear the error because its an actual NULL and not an error */ jp->error_code = PHP_JSON_ERROR_NONE; RETVAL_NULL(); - } else if (!strncasecmp(trim, "true", trim_len)) { + } else if (!strncmp(trim, "true", trim_len)) { RETVAL_BOOL(1); } - } else if (trim_len == 5 && !strncasecmp(trim, "false", trim_len)) { + } else if (trim_len == 5 && !strncmp(trim, "false", trim_len)) { RETVAL_BOOL(0); } diff --git a/ext/json/tests/bug64874_part2.phpt b/ext/json/tests/bug64874_part2.phpt new file mode 100644 index 0000000000000..e284821e8faac --- /dev/null +++ b/ext/json/tests/bug64874_part2.phpt @@ -0,0 +1,41 @@ +--TEST-- +Case-sensitivity part of bug #64874 ("json_decode handles whitespace and case-sensitivity incorrectly") +--SKIPIF-- + +--FILE-- +