[Intl] fix Locale::getFallback() throwing exception on long $locale

This commit is contained in:
bahram 2021-02-13 22:42:31 +03:30 committed by Nicolas Grekas
parent c1c20860e5
commit a89ced8eac
2 changed files with 14 additions and 1 deletions

View File

@ -68,7 +68,8 @@ final class Locale extends \Locale
public static function getFallback(string $locale): ?string
{
if (\function_exists('locale_parse')) {
$localeSubTags = locale_parse($locale);
$localeSubTags = locale_parse($locale) ?? ['language' => $locale];
if (1 === \count($localeSubTags)) {
if ('root' !== self::$defaultFallback && self::$defaultFallback === $localeSubTags['language']) {
return 'root';

View File

@ -70,4 +70,16 @@ class LocaleTest extends TestCase
Locale::setDefaultFallback($prev);
}
/**
* @requires function locale_parse
*/
public function testLongLocaleFallback()
{
$locale = 'LC_TYPE=fr_FR.UTF-8;LC_NUMERIC=C;LC_TIME=fr_FR.UTF-8;LC_COLLATE=fr_FR.UTF-8;'.
'LC_MONETARY=fr_FR.UTF-8;LC_MESSAGES=fr_FR.UTF-8;LC_PAPER=fr_FR.UTF-8;LC_NAME=fr_FR.UTF-8;'.
'LC_ADDRESS=fr_FR.UTF-8;LC_TELEPHONE=fr_FR.UTF-8;LC_MEASUREMENT=fr_FR.UTF-8;LC_IDENTIFICATION=fr_FR.UTF-8';
$this->assertNull(Locale::getFallback($locale));
}
}