Skip to content

Commit

Permalink
Issue #105 Fix missing slug params with UrlNormalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehaertl committed Apr 18, 2017
1 parent 1695f82 commit 38e7bb8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
9 changes: 7 additions & 2 deletions UrlManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,13 @@ protected function redirectToLanguage($language)
try {
$result = parent::parseRequest($this->_request);
} catch (UrlNormalizerRedirectException $e) {
$route = is_array($e->url) ? $e->url[0] : $e->url;
$result = [$route, $this->_request->getQueryParams()];
if (is_array($e->url)) {
$params = $e->url;
$route = array_shift($params);
$result = [$route, $params];
} else {
$result = [$e->url, []];
}
}
if ($result === false) {
throw new \yii\web\NotFoundHttpException(Yii::t('yii', 'Page not found.'));
Expand Down
28 changes: 28 additions & 0 deletions tests/RedirectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class RedirectTest extends TestCase
'languages' => ['en-US', 'en', 'de', 'pt', 'at' => 'de-AT', 'alias' => 'fr', 'es-BO', 'wc-*'],
'rules' => [
'/custom' => 'test/action',
'/slug/<name>' => 'test/slug',
[
'pattern' => '/slash',
'route' => 'test/slash',
Expand Down Expand Up @@ -128,6 +129,8 @@ class RedirectTest extends TestCase
'/site/page?a=b' => [
['/de/site/page?a=b', 'request' => ['acceptableLanguages' => ['de']]],
],
'/slug/value' => false,
'/en/slug/value' => '/slug/value'
],
],

Expand All @@ -138,6 +141,7 @@ class RedirectTest extends TestCase
'enableDefaultLanguageUrlCode' => true,
'rules' => [
'/custom' => 'test/action',
'/slug/<name>' => 'test/slug',
[
'pattern' => '/slash',
'route' => 'test/slash',
Expand Down Expand Up @@ -186,6 +190,8 @@ class RedirectTest extends TestCase
'/site/page?a=b' => [
['/de/site/page?a=b', 'request' => ['acceptableLanguages' => ['de']]],
],
'/slug/value' => '/en/slug/value',
'/en/slug/value' => false,
],
],

Expand Down Expand Up @@ -274,6 +280,7 @@ class RedirectTest extends TestCase
'suffix' => '/',
'rules' => [
'/custom' => 'test/action',
'/slug/<name>' => 'test/slug',
[
'pattern' => '/noslash',
'route' => 'test/slash',
Expand Down Expand Up @@ -303,6 +310,8 @@ class RedirectTest extends TestCase
'/site/page/?a=b' => [
['/de/site/page/?a=b', 'request' => ['acceptableLanguages' => ['de']]],
],
'/slug/value/' => false,
'/en/slug/value/' => '/slug/value/',
],
],
[
Expand All @@ -312,6 +321,7 @@ class RedirectTest extends TestCase
'suffix' => '/',
'rules' => [
'/custom' => 'test/action',
'/slug/<name>' => 'test/slug',
[
'pattern' => '/noslash',
'route' => 'test/slash',
Expand Down Expand Up @@ -357,6 +367,8 @@ class RedirectTest extends TestCase
'/site/page/?a=b' => [
['/de/site/page/?a=b', 'request' => ['acceptableLanguages' => ['de']]],
],
'/slug/value/' => '/en/slug/value/',
'/en/slug/value/' => false,
],
],

Expand All @@ -370,6 +382,7 @@ class RedirectTest extends TestCase
],
'rules' => [
'/custom' => 'test/action',
'/slug/<name>' => 'test/slug',
[
'pattern' => '/noslash',
'route' => 'test/slash',
Expand Down Expand Up @@ -419,6 +432,9 @@ class RedirectTest extends TestCase
'/en/noslash?a=b' => '/noslash?a=b',
'/en/noslash/?a=b' => '/noslash?a=b',
'/de/noslash/?a=b' => '/de/noslash?a=b',
'/slug/value' => '/slug/value/',
'/en/slug/value' => '/slug/value/',
'/de/slug/value' => '/de/slug/value/',
],
],
[
Expand All @@ -429,6 +445,7 @@ class RedirectTest extends TestCase
],
'rules' => [
'/custom' => 'test/action',
'/slug/<name>' => 'test/slug',
[
'pattern' => '/slash',
'route' => 'test/slash',
Expand Down Expand Up @@ -478,6 +495,9 @@ class RedirectTest extends TestCase
'/en/slash?a=b' => '/slash/?a=b',
'/en/slash/?a=b' => '/slash/?a=b',
'/de/slash?a=b' => '/de/slash/?a=b',
'/slug/value/' => '/slug/value',
'/en/slug/value/' => '/slug/value',
'/de/slug/value/' => '/de/slug/value',
],
],

Expand All @@ -492,6 +512,7 @@ class RedirectTest extends TestCase
],
'rules' => [
'/custom' => 'test/action',
'/slug/<name>' => 'test/slug',
[
'pattern' => '/noslash',
'route' => 'test/slash',
Expand Down Expand Up @@ -537,6 +558,9 @@ class RedirectTest extends TestCase
'/noslash/?a=b' => '/en/noslash?a=b',
'/en/noslash/?a=b' => '/en/noslash?a=b',
'/de/noslash/?a=b' => '/de/noslash?a=b',
'/slug/value' => '/en/slug/value/',
'/en/slug/value' => '/en/slug/value/',
'/de/slug/value' => '/de/slug/value/',
],
],
[
Expand All @@ -548,6 +572,7 @@ class RedirectTest extends TestCase
],
'rules' => [
'/custom' => 'test/action',
'/slug/<name>' => 'test/slug',
[
'pattern' => '/slash',
'route' => 'test/slash',
Expand Down Expand Up @@ -593,6 +618,9 @@ class RedirectTest extends TestCase
'/slash/?a=b' => '/en/slash/?a=b',
'/en/slash?a=b' => '/en/slash/?a=b',
'/de/slash?a=b' => '/de/slash/?a=b',
'/slug/value/' => '/en/slug/value',
'/en/slug/value/' => '/en/slug/value',
'/de/slug/value/' => '/de/slug/value',
],
],
];
Expand Down

0 comments on commit 38e7bb8

Please sign in to comment.