From 1e10475d88c0628e486850956533e3cdbb264636 Mon Sep 17 00:00:00 2001 From: Valentin Date: Thu, 21 Jun 2018 00:41:56 +0300 Subject: [PATCH] Ignore keepQueryParams attribute when generating route redirect. --- .../Controller/RedirectController.php | 2 +- .../Controller/RedirectControllerTest.php | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php index 67f60b77d690f..45811e5c42e24 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php @@ -64,7 +64,7 @@ public function redirectAction(Request $request, string $route, bool $permanent if (false === $ignoreAttributes || is_array($ignoreAttributes)) { $attributes = $request->attributes->get('_route_params'); $attributes = $keepQueryParams ? array_merge($request->query->all(), $attributes) : $attributes; - unset($attributes['route'], $attributes['permanent'], $attributes['ignoreAttributes'], $attributes['keepRequestMethod']); + unset($attributes['route'], $attributes['permanent'], $attributes['ignoreAttributes'], $attributes['keepRequestMethod'], $attributes['keepQueryParams']); if ($ignoreAttributes) { $attributes = array_diff_key($attributes, array_flip($ignoreAttributes)); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php index acb607da83a85..cb56338b388bb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php @@ -47,7 +47,7 @@ public function testEmptyRoute() /** * @dataProvider provider */ - public function testRoute($permanent, $keepRequestMethod, $ignoreAttributes, $expectedCode, $expectedAttributes) + public function testRoute($permanent, $keepRequestMethod, $keepQueryParams, $ignoreAttributes, $expectedCode, $expectedAttributes) { $request = new Request(); @@ -63,6 +63,7 @@ public function testRoute($permanent, $keepRequestMethod, $ignoreAttributes, $ex 'additional-parameter' => 'value', 'ignoreAttributes' => $ignoreAttributes, 'keepRequestMethod' => $keepRequestMethod, + 'keepQueryParams' => $keepQueryParams, ), ); @@ -77,7 +78,7 @@ public function testRoute($permanent, $keepRequestMethod, $ignoreAttributes, $ex $controller = new RedirectController($router); - $returnResponse = $controller->redirectAction($request, $route, $permanent, $ignoreAttributes, $keepRequestMethod); + $returnResponse = $controller->redirectAction($request, $route, $permanent, $ignoreAttributes, $keepRequestMethod, $keepQueryParams); $this->assertRedirectUrl($returnResponse, $url); $this->assertEquals($expectedCode, $returnResponse->getStatusCode()); @@ -86,14 +87,14 @@ public function testRoute($permanent, $keepRequestMethod, $ignoreAttributes, $ex public function provider() { return array( - array(true, false, false, 301, array('additional-parameter' => 'value')), - array(false, false, false, 302, array('additional-parameter' => 'value')), - array(false, false, true, 302, array()), - array(false, false, array('additional-parameter'), 302, array()), - array(true, true, false, 308, array('additional-parameter' => 'value')), - array(false, true, false, 307, array('additional-parameter' => 'value')), - array(false, true, true, 307, array()), - array(false, true, array('additional-parameter'), 307, array()), + array(true, false, false, false, 301, array('additional-parameter' => 'value')), + array(false, false, false, false, 302, array('additional-parameter' => 'value')), + array(false, false, false, true, 302, array()), + array(false, false, false, array('additional-parameter'), 302, array()), + array(true, true, false, false, 308, array('additional-parameter' => 'value')), + array(false, true, false, false, 307, array('additional-parameter' => 'value')), + array(false, true, false, true, 307, array()), + array(false, true, true, array('additional-parameter'), 307, array()), ); }