From: Ilia Alshanetsky Date: Mon, 1 Oct 2007 15:23:15 +0000 (+0000) Subject: MFB: Fixed bug #42785 (json_encode() formats doubles according to locale X-Git-Tag: php-5.2.5RC1~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f89aae49a7a22c6f916786c6254d174da4e6e2ff;p=php MFB: Fixed bug #42785 (json_encode() formats doubles according to locale rather then following standard syntax). --- diff --git a/NEWS b/NEWS index 98e62de309..9a6ea7fe2f 100644 --- a/NEWS +++ b/NEWS @@ -30,6 +30,8 @@ PHP NEWS Reported by Laurent gaffie. (Ilia) - Fixed imagerectangle regression with 1x1 rectangle (libgd #106). (Pierre) +- Fixed bug #42785 (json_encode() formats doubles according to locale rather + then following standard syntax). (Ilia) - Fixed bug #42767 (highlight_string() truncates trailing comment). (Ilia) - Fixed bug #42739 (mkdir() doesn't like a trailing slash when safe_mode is enabled). (Ilia) diff --git a/ext/json/json.c b/ext/json/json.c index 283021b365..4fc9ae143d 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -359,7 +359,7 @@ 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); + len = spprintf(&d, 0, "%.*k", (int) EG(precision), dbl); smart_str_appendl(buf, d, len); efree(d); } else { diff --git a/main/snprintf.c b/main/snprintf.c index 853a078885..54820e804e 100644 --- a/main/snprintf.c +++ b/main/snprintf.c @@ -1004,6 +1004,7 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) / case 'g': + case 'k': case 'G': case 'H': switch(modifier) { @@ -1045,7 +1046,7 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) / 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 68ff792cdc..ba88045a50 100644 --- a/main/spprintf.c +++ b/main/spprintf.c @@ -600,6 +600,7 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) case 'g': + case 'k': case 'G': case 'H': switch(modifier) { @@ -640,7 +641,7 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap) 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)