]> granicus.if.org Git - php/commitdiff
fix bug #14562
authorStanislav Malyshev <stas@php.net>
Fri, 30 Jan 2009 20:56:12 +0000 (20:56 +0000)
committerStanislav Malyshev <stas@php.net>
Fri, 30 Jan 2009 20:56:12 +0000 (20:56 +0000)
ext/intl/formatter/formatter_parse.c
ext/intl/tests/bug14562.phpt [new file with mode: 0755]

index 5dd2db278894d79f7cf09b738d977e7da819dd37..b73095d3e4e7c6fe4a2e1d5918127e73289f8b09 100755 (executable)
@@ -19,6 +19,7 @@
 #endif
 
 #include <unicode/ustring.h>
+#include <locale.h>
 
 #include "php_intl.h"
 #include "formatter_class.h"
@@ -26,6 +27,8 @@
 #include "formatter_parse.h"
 #include "intl_convert.h"
 
+#define ICU_LOCALE_BUG 1
+
 /* {{{ proto mixed NumberFormatter::parse( string $str[, int $type, int &$position ])
  * Parse a number. }}} */
 /* {{{ proto mixed numfmt_parse( NumberFormatter $nf, string $str[, int $type, int &$position ])
@@ -43,6 +46,7 @@ PHP_FUNCTION( numfmt_parse )
        double val_double;
        int32_t* position_p = NULL;
        zval *zposition = NULL;
+       char *oldlocale;
        FORMATTER_METHOD_INIT_VARS;
 
        /* Parse parameters. */
@@ -68,6 +72,10 @@ PHP_FUNCTION( numfmt_parse )
                position_p = &position;
        }
 
+#if ICU_LOCALE_BUG && defined(LC_NUMERIC)
+       oldlocale = setlocale(LC_NUMERIC, "C");
+#endif
+
        switch(type) {
                case FORMAT_TYPE_INT32:
                        val32 = unum_parse(FORMATTER_OBJECT(nfo), sstr, sstr_len, position_p, &INTL_DATA_ERROR_CODE(nfo));
@@ -91,6 +99,9 @@ PHP_FUNCTION( numfmt_parse )
                        RETVAL_FALSE;
                        break;
        }
+#if ICU_LOCALE_BUG && defined(LC_NUMERIC)
+       setlocale(LC_NUMERIC, oldlocale);
+#endif
        if(zposition) {
                zval_dtor(zposition);
                ZVAL_LONG(zposition, position);
diff --git a/ext/intl/tests/bug14562.phpt b/ext/intl/tests/bug14562.phpt
new file mode 100755 (executable)
index 0000000..3256268
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+Bug #14562 NumberFormatter breaks when locale changes
+--SKIPIF--
+<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
+--FILE--
+<?php
+
+function ut_main()
+{
+       $res_str = "";
+       $de_locale="de_DE.UTF-8";
+       $fmt = new NumberFormatter("de", NumberFormatter::DECIMAL );
+       $numeric = $fmt->parse("1234,56");
+       $res_str .= "$numeric\n";
+       setlocale(LC_ALL, $de_locale);
+       $fmt = new NumberFormatter("de", NumberFormatter::DECIMAL );
+       $numeric = $fmt->parse("1234,56");
+       $res_str .= "$numeric\n";
+       return $res_str;
+}
+
+include_once( 'ut_common.inc' );
+ut_run();
+
+?>
+--EXPECT--
+1234.56
+1234.56