diff --git a/UrlManager.php b/UrlManager.php index b1c8acf..ac70993 100644 --- a/UrlManager.php +++ b/UrlManager.php @@ -275,7 +275,7 @@ protected function processLocaleUrl($request) list($language,$country) = $this->matchCode($code); if ($country!==null) { if ($code==="$language-$country" && !$this->keepUppercaseLanguageCode) { - $this->redirectToLanguage(strtolower($code)); + $this->redirectToLanguage(strtolower($code)); // Redirect ll-CC to ll-cc } else { $language = "$language-$country"; } @@ -345,7 +345,7 @@ protected function processLocaleUrl($request) if ($key && is_string($key)) { $language = $key; } - $this->redirectToLanguage(strtolower($language)); + $this->redirectToLanguage($this->keepUppercaseLanguageCode ? $language : strtolower($language)); } } @@ -368,7 +368,7 @@ protected function processLocaleUrl($request) * a configured language, that language is returned. * * @param string $code the code to match - * @return array of [language, country] where both can be null if no match + * @return array of [language, country], [language, null] or [null, null] if no match */ protected function matchCode($code) { diff --git a/tests/RedirectTest.php b/tests/RedirectTest.php index b115430..5ca3246 100644 --- a/tests/RedirectTest.php +++ b/tests/RedirectTest.php @@ -208,6 +208,17 @@ public function testRedirectsIfNoLanguageInUrlAndLanguageInCookie() $this->mockRequest('/site/page'); } + public function testRedirectsNoLanguageInUrlAndUppercaseLanguageInCookieAndUppercaseEnabled() + { + $this->expectRedirect('/en-US/site/page'); + $_COOKIE['_language'] = 'en-US'; + $this->mockUrlManager( [ + 'languages' => ['en-US', 'en', 'de'], + 'keepUppercaseLanguageCode' => true, + ]); + $this->mockRequest('/site/page'); + } + public function testRedirectsIfNoLanguageInUrlAndLanguageInCookieMatchesWildcard() { $this->expectRedirect('/de/site/page');