diff --git a/NEWS b/NEWS index a4f98ff3fef..fa8ce9d774e 100644 --- a/NEWS +++ b/NEWS @@ -630,6 +630,8 @@ PHP NEWS - JSON: . Fixed bug #66021 (Blank line inside empty array/object when JSON_PRETTY_PRINT is set). (Kevin Israel) + . Fixed bug #64695 (JSON_NUMERIC_CHECK has issues with strings that are + numbers plus the letter e). (Jakub Zelenka) - LDAP: . Fixed issue with null bytes in LDAP bindings. (Matthew Daley) diff --git a/ext/json/json.c b/ext/json/json.c index 5b71eb06f6e..16af7961459 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -418,18 +418,14 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR if ((type = is_numeric_string(s, len, &p, &d, 0)) != 0) { if (type == IS_LONG) { smart_str_append_long(buf, p); - } else if (type == IS_DOUBLE) { - if (!zend_isinf(d) && !zend_isnan(d)) { - char *tmp; - int l = spprintf(&tmp, 0, "%.*k", (int) EG(precision), d); - smart_str_appendl(buf, tmp, l); - efree(tmp); - } else { - JSON_G(error_code) = PHP_JSON_ERROR_INF_OR_NAN; - smart_str_appendc(buf, '0'); - } + return; + } else if (type == IS_DOUBLE && !zend_isinf(d) && !zend_isnan(d)) { + char *tmp; + int l = spprintf(&tmp, 0, "%.*k", (int) EG(precision), d); + smart_str_appendl(buf, tmp, l); + efree(tmp); + return; } - return; } } diff --git a/ext/json/tests/bug64695.phpt b/ext/json/tests/bug64695.phpt new file mode 100644 index 00000000000..899259f4b48 --- /dev/null +++ b/ext/json/tests/bug64695.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #64695 JSON_NUMERIC_CHECK has issues with strings that are numbers plus the letter e +--SKIPIF-- + +--FILE-- + '123343e871700'); +var_dump(json_encode($t, JSON_NUMERIC_CHECK)); + +echo "Done\n"; +?> +--EXPECT-- +string(24) "{"test":"123343e871700"}" +Done