Merge branch 'PHP-7.4' into PHP-8.0

* PHP-7.4:
  Fix #79908: json_encode encodes negative zero as int
This commit is contained in:
Christoph M. Becker 2021-07-13 15:32:13 +02:00
commit 1ba190bdb3
No known key found for this signature in database
GPG key ID: D66C9593118BCCB6
3 changed files with 17 additions and 1 deletions

3
NEWS
View file

@ -23,6 +23,9 @@ PHP NEWS
. Fixed bug #68471 (IntlDateFormatter fails for "GMT+00:00" timezone). (cmb)
. Fixed bug #74264 (grapheme_strrpos() broken for negative offsets). (cmb)
- JSON:
. Fixed bug #79908 (json_encode encodes negative zero as int). (cmb)
- OpenSSL:
. Fixed bug #52093 (openssl_csr_sign truncates $serial). (cmb)

View file

@ -102,7 +102,8 @@ static inline void php_json_encode_double(smart_str *buf, double d, int options)
php_gcvt(d, (int)PG(serialize_precision), '.', 'e', num);
len = strlen(num);
if (options & PHP_JSON_PRESERVE_ZERO_FRACTION && strchr(num, '.') == NULL && len < PHP_DOUBLE_MAX_LENGTH - 2) {
if ((options & PHP_JSON_PRESERVE_ZERO_FRACTION && strchr(num, '.') == NULL && len < PHP_DOUBLE_MAX_LENGTH - 2)
|| (UNEXPECTED(len == 2 && num[0] == '-' && num[1] == '0'))) {
num[len++] = '.';
num[len++] = '0';
num[len] = '\0';

View file

@ -0,0 +1,12 @@
--TEST--
Bug #79908 (json_encode encodes negative zero as int)
--SKIPIF--
<?php
if (!extension_loaded('json')) die("skip json extension not available");
?>
--FILE--
<?php
var_dump(json_encode(-0.));
?>
--EXPECT--
string(4) "-0.0"