From: Ilia Alshanetsky Date: Mon, 1 Oct 2007 15:25:01 +0000 (+0000) Subject: MFB: Fixed bug #42785 (json_encode() formats doubles according to locale X-Git-Tag: RELEASE_2_0_0a1~1692 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6c4e9b52b98830f37d8048f2712bbb3911d10536;p=php MFB: Fixed bug #42785 (json_encode() formats doubles according to locale rather then following standard syntax). --- diff --git a/ext/json/json.c b/ext/json/json.c index cd1d285692..4b36637590 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -363,9 +363,9 @@ static void json_encode_r(smart_str *buf, zval *val TSRMLS_DC) /* {{{ */ double dbl = Z_DVAL_P(val); if (!zend_isinf(dbl) && !zend_isnan(dbl)) { - len = spprintf(&d, 0, "%.*g", (int) EG(precision), dbl); - smart_str_appendl(buf, d, len); - efree(d); + len = spprintf(&d, 0, "%.*k", (int) EG(precision), dbl); + smart_str_appendl(buf, d, len); + efree(d); } else { zend_error(E_WARNING, "[json] (json_encode_r) double %.9g does not conform to the JSON spec, encoded as 0.", dbl); smart_str_appendc(buf, '0'); diff --git a/main/snprintf.c b/main/snprintf.c index f24b146944..d70286fa5a 100644 --- a/main/snprintf.c +++ b/main/snprintf.c @@ -1051,6 +1051,7 @@ fmt_string: case 'g': + case 'k': case 'G': case 'H': switch(modifier) { @@ -1091,7 +1092,7 @@ fmt_string: lconv = localeconv(); } #endif - s = php_gcvt(fp_num, precision, *fmt=='H' ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]); + s = php_gcvt(fp_num, precision, (*fmt == 'H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]); if (*s == '-') prefix_char = *s++; else if (print_sign) diff --git a/main/spprintf.c b/main/spprintf.c index 6e2661c4f4..26052150a6 100644 --- a/main/spprintf.c +++ b/main/spprintf.c @@ -690,6 +690,7 @@ fmt_string: case 'g': + case 'k': case 'G': case 'H': switch(modifier) { @@ -730,7 +731,7 @@ fmt_string: lconv = localeconv(); } #endif - s = php_gcvt(fp_num, precision, *fmt=='H' ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]); + s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]); if (*s == '-') prefix_char = *s++; else if (print_sign)