diff --git a/NEWS b/NEWS index d814f002715..b170fbe7a83 100644 --- a/NEWS +++ b/NEWS @@ -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) diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c index 92e4a109339..8e0a72768fd 100644 --- a/ext/json/json_encoder.c +++ b/ext/json/json_encoder.c @@ -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'; diff --git a/ext/json/tests/bug79908.phpt b/ext/json/tests/bug79908.phpt new file mode 100644 index 00000000000..b2aea31069a --- /dev/null +++ b/ext/json/tests/bug79908.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #79908 (json_encode encodes negative zero as int) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +string(4) "-0.0"