Skip to content

Commit 591dbca

Browse files
committed
Fix bug #64695 (JSON_NUMERIC_CHECK has issues with strings that are numbers plus the letter e)
1 parent 7ea5b3f commit 591dbca

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,8 @@ PHP NEWS
630630
- JSON:
631631
. Fixed bug #66021 (Blank line inside empty array/object when
632632
JSON_PRETTY_PRINT is set). (Kevin Israel)
633+
. Fixed bug #64695 (JSON_NUMERIC_CHECK has issues with strings that are
634+
numbers plus the letter e). (Jakub Zelenka)
633635

634636
- LDAP:
635637
. Fixed issue with null bytes in LDAP bindings. (Matthew Daley)

ext/json/json.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -418,18 +418,14 @@ static void json_escape_string(smart_str *buf, char *s, int len, int options TSR
418418
if ((type = is_numeric_string(s, len, &p, &d, 0)) != 0) {
419419
if (type == IS_LONG) {
420420
smart_str_append_long(buf, p);
421-
} else if (type == IS_DOUBLE) {
422-
if (!zend_isinf(d) && !zend_isnan(d)) {
423-
char *tmp;
424-
int l = spprintf(&tmp, 0, "%.*k", (int) EG(precision), d);
425-
smart_str_appendl(buf, tmp, l);
426-
efree(tmp);
427-
} else {
428-
JSON_G(error_code) = PHP_JSON_ERROR_INF_OR_NAN;
429-
smart_str_appendc(buf, '0');
430-
}
421+
return;
422+
} else if (type == IS_DOUBLE && !zend_isinf(d) && !zend_isnan(d)) {
423+
char *tmp;
424+
int l = spprintf(&tmp, 0, "%.*k", (int) EG(precision), d);
425+
smart_str_appendl(buf, tmp, l);
426+
efree(tmp);
427+
return;
431428
}
432-
return;
433429
}
434430

435431
}

ext/json/tests/bug64695.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #64695 JSON_NUMERIC_CHECK has issues with strings that are numbers plus the letter e
3+
--SKIPIF--
4+
<?php if (!extension_loaded("json")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
$t = array('test' => '123343e871700');
8+
var_dump(json_encode($t, JSON_NUMERIC_CHECK));
9+
10+
echo "Done\n";
11+
?>
12+
--EXPECT--
13+
string(24) "{"test":"123343e871700"}"
14+
Done

0 commit comments

Comments
 (0)