bug #40162 [Intl] fix Locale::getFallback() throwing exception on long $locale (AmirHo3ein13)
This PR was squashed before being merged into the 4.4 branch.
Discussion
----------
[Intl] fix Locale::getFallback() throwing exception on long $locale
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix #39100
| License | MIT
| Doc PR |
`Locale::getFallback()` throws an exception when the `$locale` length is greater than `INTL_MAX_LOCALE_LEN` so I added a condition to check if locale_parse return null, the `Locale::getFallback()` don't call `\count` function and just return null instead.
Commits
-------
a89ced8eac
[Intl] fix Locale::getFallback() throwing exception on long $locale
This commit is contained in:
commit
9765b5ab86
@ -68,7 +68,8 @@ final class Locale extends \Locale
|
|||||||
public static function getFallback(string $locale): ?string
|
public static function getFallback(string $locale): ?string
|
||||||
{
|
{
|
||||||
if (\function_exists('locale_parse')) {
|
if (\function_exists('locale_parse')) {
|
||||||
$localeSubTags = locale_parse($locale);
|
$localeSubTags = locale_parse($locale) ?? ['language' => $locale];
|
||||||
|
|
||||||
if (1 === \count($localeSubTags)) {
|
if (1 === \count($localeSubTags)) {
|
||||||
if ('root' !== self::$defaultFallback && self::$defaultFallback === $localeSubTags['language']) {
|
if ('root' !== self::$defaultFallback && self::$defaultFallback === $localeSubTags['language']) {
|
||||||
return 'root';
|
return 'root';
|
||||||
|
@ -70,4 +70,16 @@ class LocaleTest extends TestCase
|
|||||||
|
|
||||||
Locale::setDefaultFallback($prev);
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user