Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9765b5a

Browse filesBrowse files
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 ------- a89ced8 [Intl] fix Locale::getFallback() throwing exception on long $locale
2 parents 1a5aec1 + a89ced8 commit 9765b5a
Copy full SHA for 9765b5a

File tree

2 files changed

+14
-1
lines changed
Filter options

2 files changed

+14
-1
lines changed

‎src/Symfony/Component/Intl/Locale.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Locale.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public static function getDefaultFallback(): ?string
6868
public static function getFallback(string $locale): ?string
6969
{
7070
if (\function_exists('locale_parse')) {
71-
$localeSubTags = locale_parse($locale);
71+
$localeSubTags = locale_parse($locale) ?? ['language' => $locale];
72+
7273
if (1 === \count($localeSubTags)) {
7374
if ('root' !== self::$defaultFallback && self::$defaultFallback === $localeSubTags['language']) {
7475
return 'root';

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Tests/LocaleTest.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,16 @@ public function testDefaultRootFallback()
7070

7171
Locale::setDefaultFallback($prev);
7272
}
73+
74+
/**
75+
* @requires function locale_parse
76+
*/
77+
public function testLongLocaleFallback()
78+
{
79+
$locale = 'LC_TYPE=fr_FR.UTF-8;LC_NUMERIC=C;LC_TIME=fr_FR.UTF-8;LC_COLLATE=fr_FR.UTF-8;'.
80+
'LC_MONETARY=fr_FR.UTF-8;LC_MESSAGES=fr_FR.UTF-8;LC_PAPER=fr_FR.UTF-8;LC_NAME=fr_FR.UTF-8;'.
81+
'LC_ADDRESS=fr_FR.UTF-8;LC_TELEPHONE=fr_FR.UTF-8;LC_MEASUREMENT=fr_FR.UTF-8;LC_IDENTIFICATION=fr_FR.UTF-8';
82+
83+
$this->assertNull(Locale::getFallback($locale));
84+
}
7385
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.