]> granicus.if.org Git - php/commitdiff
Fixed bug #41567 (json_encode() double conversion is inconsistent with PHP).
authorIlia Alshanetsky <iliaa@php.net>
Mon, 4 Jun 2007 23:51:32 +0000 (23:51 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 4 Jun 2007 23:51:32 +0000 (23:51 +0000)
NEWS
ext/json/json.c
ext/json/tests/bug41567.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 1a281c16e3ec2288b143b9bf4269c420e0117049..6a585f9cefc10b496f0d940b3a444d219af4ae2d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,8 @@ PHP                                                                        NEWS
   GD_RELEASE_VERSION, GD_EXTRA_VERSION and GD_VERSION_STRING. (Pierre)
 - Fixed bug #41576 (configure failure when using --without-apxs or some
   other SAPIs disabling options). (Jani)
+- Fixed bug #41567 (json_encode() double conversion is inconsistent with
+  PHP). (Lucas, Ilia)
 - Fixed bug #41555 (configure failure: regression caused by fix for #41265).
   (Jani)
 - Fixed bug #41518 (file_exists() warns of open_basedir restriction on 
index fefdf9601e540005eb91f2fecd3cc070559aa018..737421f5aca452cc216ac3d500b633aaff937b7f 100644 (file)
@@ -354,7 +354,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, "%.9g", dbl);
+                       len = spprintf(&d, 0, "%.*g", (int) EG(precision), dbl);
                        if (d) {
                                if (dbl > LONG_MAX && !memchr(d, '.', len)) {
                                        smart_str_append_unsigned(buf, (unsigned long)Z_DVAL_P(val));
diff --git a/ext/json/tests/bug41567.phpt b/ext/json/tests/bug41567.phpt
new file mode 100644 (file)
index 0000000..837c360
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Bug #41567 (json_encode() double conversion is inconsistent with PHP)
+--FILE--
+<?php
+
+$a = json_encode(123456789.12345);
+var_dump(json_decode($a));
+
+echo "Done\n";
+?>
+--EXPECT--     
+float(123456789.12345)
+Done