Fix bug #64695 (JSON_NUMERIC_CHECK has issues with strings that are numbers plus the letter e)

This commit is contained in:
Jakub Zelenka 2015-02-22 20:22:47 +00:00
parent 7ea5b3f71c
commit 591dbcabe5
3 changed files with 23 additions and 11 deletions

2
NEWS
View File

@ -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)

View File

@ -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;
}
}

View File

@ -0,0 +1,14 @@
--TEST--
Bug #64695 JSON_NUMERIC_CHECK has issues with strings that are numbers plus the letter e
--SKIPIF--
<?php if (!extension_loaded("json")) print "skip"; ?>
--FILE--
<?php
$t = array('test' => '123343e871700');
var_dump(json_encode($t, JSON_NUMERIC_CHECK));
echo "Done\n";
?>
--EXPECT--
string(24) "{"test":"123343e871700"}"
Done