diff options
author | Anatol Belski <ab@php.net> | 2016-04-09 18:22:57 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2016-04-09 18:24:42 +0200 |
commit | ef17343b3cb9195437d760ec21dcdf6004a85b67 (patch) | |
tree | b275f1045002574c6e7c171fae9ed265570ee3b5 | |
parent | c6c44c36298d573932f153071f3bb20007924173 (diff) | |
download | php-git-ef17343b3cb9195437d760ec21dcdf6004a85b67.tar.gz |
Fixed bug #66289 Locale::lookup incorrectly returns en or en_US if locale is empty
-rw-r--r-- | ext/intl/locale/locale_methods.c | 6 | ||||
-rw-r--r-- | ext/intl/tests/locale_bug66289.phpt | 27 |
2 files changed, 32 insertions, 1 deletions
diff --git a/ext/intl/locale/locale_methods.c b/ext/intl/locale/locale_methods.c index c47f283201..3471ba4053 100644 --- a/ext/intl/locale/locale_methods.c +++ b/ext/intl/locale/locale_methods.c @@ -1548,7 +1548,11 @@ PHP_FUNCTION(locale_lookup) } if(loc_range_len == 0) { - loc_range = intl_locale_get_default(); + if(fallback_loc_str) { + loc_range = ZSTR_VAL(fallback_loc_str); + } else { + loc_range = intl_locale_get_default(); + } } hash_arr = Z_ARRVAL_P(arr); diff --git a/ext/intl/tests/locale_bug66289.phpt b/ext/intl/tests/locale_bug66289.phpt new file mode 100644 index 0000000000..6afd821b5a --- /dev/null +++ b/ext/intl/tests/locale_bug66289.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #66289 Locale::lookup incorrectly returns en or en_US if locale is empty +--SKIPIF-- +<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?> +--FILE-- +<?php + +ini_set("intl.default_locale", "en-US"); +$availableLocales = array('fr_FR', 'de', 'es_ES', 'es_419', 'en_US'); +var_dump(locale_lookup($availableLocales, false, true, 'fr_FR')); +var_dump(locale_lookup($availableLocales, false, true, null)); + +$availableLocales = array('fr_FR', 'de', 'es_ES', 'es_419'); +var_dump(locale_lookup($availableLocales, false, true, 'fr_FR')); + +ini_set("intl.default_locale", "de-DE"); +$availableLocales = array(Locale::getDefault()); +var_dump(locale_lookup($availableLocales, false, true)); + +?> +==DONE== +--EXPECT-- +string(5) "fr_fr" +string(5) "en_us" +string(5) "fr_fr" +string(5) "de_de" +==DONE== |