]> granicus.if.org Git - php/commitdiff
Fix bug #67052 (NumberFormatter::parse() resets LC_NUMERIC setting)
authorStanislav Malyshev <stas@php.net>
Mon, 7 Jul 2014 07:36:57 +0000 (00:36 -0700)
committerStanislav Malyshev <stas@php.net>
Mon, 7 Jul 2014 07:36:57 +0000 (00:36 -0700)
NEWS
ext/intl/formatter/formatter_parse.c
ext/intl/tests/bug14562.phpt
ext/intl/tests/bug67052.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 44196a3e1a6617f29a7dfa4d2ff323b11f99e26f..3fb47817f0b163f00b171dc753e2507d7f8a7e20 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,7 +16,11 @@ PHP                                                                        NEWS
     (Adam)
 
 - FPM:
-  . Fix bug #67531 (syslog cannot be set in pool configuration). (Remi)
+  . Fixed bug #67531 (syslog cannot be set in pool configuration). (Remi)
+
+- Intl:
+  . Fixed bug #67052 (NumberFormatter::parse() resets LC_NUMERIC setting). 
+    (Stas)
 
 - pgsql:
   . Fix bug #67550 (Error in code "form" instead of "from", pgsql.c, line 756),
index 6f3a3a12b5b7afcfc24ccd5332be09c58e1dd1e3..0c8704d95c45f5a9144f76965ddf6b2dca3aeabb 100644 (file)
@@ -73,7 +73,9 @@ PHP_FUNCTION( numfmt_parse )
        }
 
 #if ICU_LOCALE_BUG && defined(LC_NUMERIC)
-       oldlocale = setlocale(LC_NUMERIC, "C");
+       /* need to copy here since setlocale may change it later */
+       oldlocale = estrdup(setlocale(LC_NUMERIC, NULL));
+       setlocale(LC_NUMERIC, "C");
 #endif
 
        switch(type) {
@@ -100,6 +102,7 @@ PHP_FUNCTION( numfmt_parse )
        }
 #if ICU_LOCALE_BUG && defined(LC_NUMERIC)
        setlocale(LC_NUMERIC, oldlocale);
+       efree(oldlocale);
 #endif
        if(zposition) {
                zval_dtor(zposition);
index 32562684055428f7856e6ca58df3d31b235b40c1..7cf927f7e7a76a9af2e79c420ad2de97632cc8fc 100644 (file)
@@ -15,6 +15,7 @@ function ut_main()
        setlocale(LC_ALL, $de_locale);
        $fmt = new NumberFormatter("de", NumberFormatter::DECIMAL );
        $numeric = $fmt->parse("1234,56");
+       setlocale(LC_ALL, "C"); // reset for printing
        $res_str .= "$numeric\n";
        return $res_str;
 }
diff --git a/ext/intl/tests/bug67052.phpt b/ext/intl/tests/bug67052.phpt
new file mode 100644 (file)
index 0000000..5957939
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Bug #67052 - NumberFormatter::parse() resets LC_NUMERIC setting
+--SKIPIF--
+<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
+--FILE--
+<?php
+
+function ut_main()
+{
+       setlocale(LC_ALL, 'sl_SI.UTF-8');
+
+       $fmt = new NumberFormatter( 'sl_SI.UTF-8', NumberFormatter::DECIMAL);
+       $num = "1.234.567,891";
+       $res_str =  $fmt->parse($num)."\n";
+       $res_str .=  setlocale(LC_NUMERIC, 0);
+       return $res_str;
+}
+
+include_once( 'ut_common.inc' );
+ut_run();
+
+?>
+--EXPECT--
+1234567,891
+sl_SI.UTF-8