]> 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:23:15 +0000 (15:23 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 1 Oct 2007 15:23:15 +0000 (15:23 +0000)
rather then following standard syntax).

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

diff --git a/NEWS b/NEWS
index 98e62de309ce46181894cb2fa5daf993f9fac2f1..9a6ea7fe2ff348ec5cc16419695f14faea32b3b2 100644 (file)
--- 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)
index 283021b36506b60f2c06d33841530dd0790dd4b9..4fc9ae143db57cf11e61c324619c4becdd51ee20 100644 (file)
@@ -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 {
index 853a078885164fb3e09c8e611ad2890ecf4c4998..54820e804ec6a8954414244155e5d9af0e3a9923 100644 (file)
@@ -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) {
index 68ff792cdc263eefca8d27282fa81a227418ef4e..ba88045a50c09556b4b9aaa3bc28995121fef864 100644 (file)
@@ -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)