Skip to content

Commit

Permalink
Issue #59 Fix lowercase redirect to default language
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehaertl committed Feb 27, 2016
1 parent d7aaa53 commit ff3cfcc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions UrlManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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)
{
Expand Down
11 changes: 11 additions & 0 deletions tests/RedirectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit ff3cfcc

Please sign in to comment.