]> granicus.if.org Git - php/commitdiff
MFB: Fixed bug #42785 (json_encode() formats doubles according to locale
authorIlia Alshanetsky <iliaa@php.net>
Mon, 1 Oct 2007 15:25:01 +0000 (15:25 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 1 Oct 2007 15:25:01 +0000 (15:25 +0000)
rather then following standard syntax).

ext/json/json.c
main/snprintf.c
main/spprintf.c

index cd1d285692a43433b5570517d90d7ed11eb3f358..4b36637590bae849adcd4331a89e485f0118d848 100644 (file)
@@ -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');
index f24b1469445afbbd45e2356c13b5ceed627b9a81..d70286fa5a42bf533dd8d1ae23c100ea1f2728d8 100644 (file)
@@ -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)
index 6e2661c4f40608a84c51f0cdce1a4acbb82839b0..26052150a613be361d5633469c2fa96afea00efb 100644 (file)
@@ -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)