]> granicus.if.org Git - php/commitdiff
Fixed bug #39873 (number_format() breaks with locale & decimal points).
authorIlia Alshanetsky <iliaa@php.net>
Fri, 22 Dec 2006 04:03:15 +0000 (04:03 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Fri, 22 Dec 2006 04:03:15 +0000 (04:03 +0000)
NEWS
ext/standard/math.c
ext/standard/tests/strings/bug39873.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 3244b032850daba7c61e9f3ed0ad2ddaf14b9770..538ad3226ff1d70b21b19e2abf63827517c49cc7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,8 @@ PHP                                                                        NEWS
 - Fixed bug #39903 (Notice message when executing __halt_compiler() more than 
   once). (Tony)
 - Fixed bug #39898 (FILTER_VALIDATE_URL validates \r\n\t etc). (Ilia)
+- Fixed bug #39873 (number_format() breaks with locale & decimal points).
+  (Ilia)
 - Fixed bug #39869 (safe_read does not initialize errno).
   (michiel at boland dot org, Dmitry)
 - Fixed bug #39850 (SplFileObject throws contradictory/wrong error messages 
index c9fcee48fbe446e4ac9225c391abba9041cf4cc9..79a16938680a25597dd94850d73374d82bedae97 100644 (file)
@@ -983,7 +983,11 @@ PHPAPI char *_php_math_number_format(double d, int dec, char dec_point, char tho
        }
 
        /* find decimal point, if expected */
-       dp = dec ? strchr(tmpbuf, '.') : NULL;
+       if (dec) {
+               dp = strpbrk(tmpbuf, ".,");
+       } else {
+               dp = NULL;
+       }
 
        /* calculate the length of the return buffer */
        if (dp) {
diff --git a/ext/standard/tests/strings/bug39873.phpt b/ext/standard/tests/strings/bug39873.phpt
new file mode 100644 (file)
index 0000000..e73f3c8
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Bug #39873 (number_format() breaks with locale & decimal points)
+--SKIPIF--
+<?php
+if (!setlocale(LC_ALL, "ita","it","Italian","it_IT","it_IT.ISO8859-1","it_IT.ISO_8859-1")) {
+        die("skip locale needed for this test is not supported on this platform");
+}
+?>
+--FILE--
+<?php
+       setlocale(LC_ALL, "ita","it","Italian","it_IT","it_IT.ISO8859-1","it_IT.ISO_8859-1");
+       $num = 0+"1234.56";  
+       echo number_format($num,2);
+       echo "\n";
+?>
+--EXPECT--
+1,234.56