Skip to content

Commit f833167

Browse files
bug symfony#27664 [FrameworkBundle] Ignore keepQueryParams attribute when generating route redirect (vudaltsov)
This PR was merged into the 4.1 branch. Discussion ---------- [FrameworkBundle] Ignore keepQueryParams attribute when generating route redirect | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Prevents keepQueryParams from appearing in query. Commits ------- 1e10475 Ignore keepQueryParams attribute when generating route redirect.
2 parents e1f2c3c + 1e10475 commit f833167

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function redirectAction(Request $request, string $route, bool $permanent
6464
if (false === $ignoreAttributes || is_array($ignoreAttributes)) {
6565
$attributes = $request->attributes->get('_route_params');
6666
$attributes = $keepQueryParams ? array_merge($request->query->all(), $attributes) : $attributes;
67-
unset($attributes['route'], $attributes['permanent'], $attributes['ignoreAttributes'], $attributes['keepRequestMethod']);
67+
unset($attributes['route'], $attributes['permanent'], $attributes['ignoreAttributes'], $attributes['keepRequestMethod'], $attributes['keepQueryParams']);
6868
if ($ignoreAttributes) {
6969
$attributes = array_diff_key($attributes, array_flip($ignoreAttributes));
7070
}

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testEmptyRoute()
4747
/**
4848
* @dataProvider provider
4949
*/
50-
public function testRoute($permanent, $keepRequestMethod, $ignoreAttributes, $expectedCode, $expectedAttributes)
50+
public function testRoute($permanent, $keepRequestMethod, $keepQueryParams, $ignoreAttributes, $expectedCode, $expectedAttributes)
5151
{
5252
$request = new Request();
5353

@@ -63,6 +63,7 @@ public function testRoute($permanent, $keepRequestMethod, $ignoreAttributes, $ex
6363
'additional-parameter' => 'value',
6464
'ignoreAttributes' => $ignoreAttributes,
6565
'keepRequestMethod' => $keepRequestMethod,
66+
'keepQueryParams' => $keepQueryParams,
6667
),
6768
);
6869

@@ -77,7 +78,7 @@ public function testRoute($permanent, $keepRequestMethod, $ignoreAttributes, $ex
7778

7879
$controller = new RedirectController($router);
7980

80-
$returnResponse = $controller->redirectAction($request, $route, $permanent, $ignoreAttributes, $keepRequestMethod);
81+
$returnResponse = $controller->redirectAction($request, $route, $permanent, $ignoreAttributes, $keepRequestMethod, $keepQueryParams);
8182

8283
$this->assertRedirectUrl($returnResponse, $url);
8384
$this->assertEquals($expectedCode, $returnResponse->getStatusCode());
@@ -86,14 +87,14 @@ public function testRoute($permanent, $keepRequestMethod, $ignoreAttributes, $ex
8687
public function provider()
8788
{
8889
return array(
89-
array(true, false, false, 301, array('additional-parameter' => 'value')),
90-
array(false, false, false, 302, array('additional-parameter' => 'value')),
91-
array(false, false, true, 302, array()),
92-
array(false, false, array('additional-parameter'), 302, array()),
93-
array(true, true, false, 308, array('additional-parameter' => 'value')),
94-
array(false, true, false, 307, array('additional-parameter' => 'value')),
95-
array(false, true, true, 307, array()),
96-
array(false, true, array('additional-parameter'), 307, array()),
90+
array(true, false, false, false, 301, array('additional-parameter' => 'value')),
91+
array(false, false, false, false, 302, array('additional-parameter' => 'value')),
92+
array(false, false, false, true, 302, array()),
93+
array(false, false, false, array('additional-parameter'), 302, array()),
94+
array(true, true, false, false, 308, array('additional-parameter' => 'value')),
95+
array(false, true, false, false, 307, array('additional-parameter' => 'value')),
96+
array(false, true, false, true, 307, array()),
97+
array(false, true, true, array('additional-parameter'), 307, array()),
9798
);
9899
}
99100

0 commit comments

Comments
 (0)