Skip to content

Commit 05070df

Browse files
committed
[Intl] fix #39100
locale_parse returns null if `$locale` length is greater than `INTL_MAX_LOCALE_LEN`. Set `$localeSubTags = ['language' => $locale]` if so.
1 parent f1f4ea9 commit 05070df

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

src/Symfony/Component/Intl/Locale.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,7 @@ public static function getDefaultFallback(): ?string
6868
public static function getFallback(string $locale): ?string
6969
{
7070
if (\function_exists('locale_parse')) {
71-
if (null === $localeSubTags = locale_parse($locale)) {
72-
if (\defined('INTL_MAX_LOCALE_LEN')) {
73-
$message = sprintf('The length of $locale must be less than %s', \INTL_MAX_LOCALE_LEN);
74-
}
75-
76-
throw new \InvalidArgumentException($message ?? '');
77-
}
71+
$localeSubTags = locale_parse($locale) ?? ['language' => $locale];
7872

7973
if (1 === \count($localeSubTags)) {
8074
if ('root' !== self::$defaultFallback && self::$defaultFallback === $localeSubTags['language']) {

src/Symfony/Component/Intl/Tests/LocaleTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ public function testLongLocaleFallback()
8080
'LC_MONETARY=fr_FR.UTF-8;LC_MESSAGES=fr_FR.UTF-8;LC_PAPER=fr_FR.UTF-8;LC_NAME=fr_FR.UTF-8;'.
8181
'LC_ADDRESS=fr_FR.UTF-8;LC_TELEPHONE=fr_FR.UTF-8;LC_MEASUREMENT=fr_FR.UTF-8;LC_IDENTIFICATION=fr_FR.UTF-8';
8282

83-
$this->expectException(\InvalidArgumentException::class);
84-
Locale::getFallback($locale);
83+
$this->assertNull(Locale::getFallback($locale));
8584
}
8685
}

0 commit comments

Comments
 (0)