Skip to content

Commit 7df2824

Browse files
Improve locale validation in IncomingRequest
Enhanced locale validation to check for language-only locales before falling back to the default.
1 parent 88c29bc commit 7df2824

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

system/HTTP/IncomingRequest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,14 @@ public function getPath(): string
441441
*/
442442
public function setLocale(string $locale)
443443
{
444-
// If it's not a valid locale, set it
445-
// to the default locale for the site.
444+
// Check if valid locale.
446445
if (! in_array($locale, $this->validLocales, true)) {
447-
$locale = $this->defaultLocale;
446+
// If not valid, check if language only is valid locale.
447+
$locale = strtok($locale, '-');
448+
if (! in_array($locale, $this->validLocales, true)) {
449+
// If neither valid, use default locale for the site.
450+
$locale = $this->defaultLocale;
451+
}
448452
}
449453

450454
$this->locale = $locale;

0 commit comments

Comments
 (0)