Skip to content

Commit 36cf6a2

Browse files
author
Ilia Alshanetsky
committed
Fixed bug #42785 (json_encode() formats doubles according to locale rather then following standard syntax).
1 parent 5f15b1e commit 36cf6a2

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

ext/json/json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ static void json_encode_r(smart_str *buf, zval *val TSRMLS_DC) /* {{{ */
359359
double dbl = Z_DVAL_P(val);
360360

361361
if (!zend_isinf(dbl) && !zend_isnan(dbl)) {
362-
len = spprintf(&d, 0, "%.*g", (int) EG(precision), dbl);
362+
len = spprintf(&d, 0, "%.*k", (int) EG(precision), dbl);
363363
smart_str_appendl(buf, d, len);
364364
efree(d);
365365
} else {

main/snprintf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
10041004

10051005

10061006
case 'g':
1007+
case 'k':
10071008
case 'G':
10081009
case 'H':
10091010
switch(modifier) {
@@ -1045,7 +1046,7 @@ static int format_converter(register buffy * odp, const char *fmt, va_list ap) /
10451046
lconv = localeconv();
10461047
}
10471048
#endif
1048-
s = php_gcvt(fp_num, precision, *fmt=='H' ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]);
1049+
s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]);
10491050
if (*s == '-') {
10501051
prefix_char = *s++;
10511052
} else if (print_sign) {

main/spprintf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap)
600600

601601

602602
case 'g':
603+
case 'k':
603604
case 'G':
604605
case 'H':
605606
switch(modifier) {
@@ -640,7 +641,7 @@ static void xbuf_format_converter(smart_str *xbuf, const char *fmt, va_list ap)
640641
lconv = localeconv();
641642
}
642643
#endif
643-
s = php_gcvt(fp_num, precision, *fmt=='H' ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]);
644+
s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]);
644645
if (*s == '-')
645646
prefix_char = *s++;
646647
else if (print_sign)

0 commit comments

Comments
 (0)