diff --git a/src/Controller/RedirectController.php b/src/Controller/RedirectController.php index 632399c1..3d60bea8 100644 --- a/src/Controller/RedirectController.php +++ b/src/Controller/RedirectController.php @@ -61,7 +61,6 @@ class RedirectController extends AbstractController $locale = $user->getLanguage(); } - //$new_url = str_replace($request->getPathInfo(), '/' . $locale . $request->getPathInfo(), $request->getUri()); $new_url = $request->getUriForPath('/'.$locale.$request->getPathInfo()); //If either mod_rewrite is not enabled or the index.php version is enforced, add index.php to the string @@ -71,6 +70,9 @@ class RedirectController extends AbstractController $new_url = $request->getSchemeAndHttpHost().$request->getBaseUrl().'/index.php/'.$locale.$request->getPathInfo(); } + //Add the query string + $new_url .= $request->getQueryString() ? '?'.$request->getQueryString() : ''; + return $this->redirect($new_url); } diff --git a/tests/Controller/RedirectControllerTest.php b/tests/Controller/RedirectControllerTest.php index 69b197e3..59e884d3 100644 --- a/tests/Controller/RedirectControllerTest.php +++ b/tests/Controller/RedirectControllerTest.php @@ -91,6 +91,9 @@ class RedirectControllerTest extends WebTestCase //Without an explicit set value, the user should be redirect to english version [null, '/', '/en/'], ['en_US', '/part/3', '/en_US/part/3'], + //Test that query parameters work + ['de', '/dialog?target_id=133&target_type=part', '/de/dialog?target_id=133&target_type=part'], + ['en', '/dialog?storelocation=1', '/en/dialog?storelocation=1'], ]; } @@ -99,13 +102,13 @@ class RedirectControllerTest extends WebTestCase * * @dataProvider urlAddLocaleDataProvider * @group slow - * @depends testUrlMatch + * @depends testUrlMatch * - * @param $user_locale - * @param $input_path - * @param $redirect_path + * @param string|null $user_locale + * @param string $input_path + * @param string $redirect_path */ - public function testAddLocale($user_locale, $input_path, $redirect_path): void + public function testAddLocale(?string $user_locale, string $input_path, string $redirect_path): void { //Redirect path is absolute $redirect_path = 'http://localhost'.$redirect_path;