]> granicus.if.org Git - php/commitdiff
Fixed bug #73793 (WDDX uses wrong decimal seperator)
authorChristoph M. Becker <cmbecker69@gmx.de>
Sun, 13 Aug 2017 18:51:53 +0000 (20:51 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Sun, 13 Aug 2017 18:51:53 +0000 (20:51 +0200)
The WDDX specification[1] requires to serialize floats with a decimal
point, but `snprintf()` is locale-dependent and may use a decimal
comma. We fix that afterwards by replacing an eventual comma with a
point.

[1] <http://xml.coverpages.org/wddx0090-dtd-19980928.txt>

NEWS
ext/wddx/tests/bug73793.phpt [new file with mode: 0644]
ext/wddx/wddx.c

diff --git a/NEWS b/NEWS
index 8920376b4d207f4e5337a626ce69481d2cb7c650..0723d9923179cba7cc7665618ba6abac2775dfd3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -58,6 +58,9 @@ PHP                                                                        NEWS
   . Fixed bug #75054 (A Denial of Service Vulnerability was found when
     performing deserialization). (Nikita)
 
+- WDDX:
+  . Fixed bug #73793 (WDDX uses wrong decimal seperator). (cmb)
+
 - XMLRPC:
   . Fixed bug #74975 (Incorrect xmlrpc serialization for classes with declared
     properties). (blar)
diff --git a/ext/wddx/tests/bug73793.phpt b/ext/wddx/tests/bug73793.phpt
new file mode 100644 (file)
index 0000000..fed4b35
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #73793 (WDDX uses wrong decimal seperator)
+--SKIPIF--
+<?php
+if (!extension_loaded('wddx')) print 'skip wddx extension not available';
+if (setlocale(LC_NUMERIC, ['de_DE', 'de_DE.UTF-8', 'de-DE']) === false) {
+    print 'skip German locale not available';
+}
+?>
+--FILE--
+<?php
+setlocale(LC_NUMERIC , ['de_DE', 'de_DE.UTF-8', 'de-DE']);
+var_dump(wddx_serialize_value(['foo' => 5.1]));
+?>
+===DONE===
+--EXPECT--
+string(120) "<wddxPacket version='1.0'><header/><data><struct><var name='foo'><number>5.1</number></var></struct></data></wddxPacket>"
+===DONE===
index c1fe0204a58269c415bec2a29716bb323d2b6d8e..d67ee47c2a2265378babd73a7f07503a474227ee 100644 (file)
@@ -420,11 +420,15 @@ static void php_wddx_serialize_string(wddx_packet *packet, zval *var)
  */
 static void php_wddx_serialize_number(wddx_packet *packet, zval *var)
 {
-       char tmp_buf[WDDX_BUF_LEN];
+       char tmp_buf[WDDX_BUF_LEN], *dec_point;
        zend_string *str = zval_get_string(var);
        snprintf(tmp_buf, sizeof(tmp_buf), WDDX_NUMBER, ZSTR_VAL(str));
        zend_string_release(str);
 
+       dec_point = strchr(tmp_buf, ',');
+       if (dec_point) {
+               *dec_point = '.';
+       }
        php_wddx_add_chunk(packet, tmp_buf);
 }
 /* }}} */