-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] keep query in redirect #26281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FrameworkBundle] keep query in redirect #26281
Conversation
Simperfit
commented
Feb 23, 2018
•
edited by javiereguiluz
Loading
edited by javiereguiluz
Q | A |
---|---|
Branch? | 4.1 |
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | #26256 |
License | MIT |
Doc PR | symfony/symfony-docs#9314 |
c8c18f2
to
a400739
Compare
5fe9639
to
5f3b11e
Compare
* @param string $route The route name to redirect to | ||
* @param bool $permanent Whether the redirection is permanent | ||
* @param bool|array $ignoreAttributes Whether to ignore attributes or an array of attributes to ignore | ||
* @param bool $keepRequestMethod Wheter redirect action should keep HTTP request method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be fixed on 2.7 instead, see #25859 in progress
@@ -78,7 +78,6 @@ public function testRoute($permanent, $keepRequestMethod, $ignoreAttributes, $ex | |||
$controller = new RedirectController($router); | |||
|
|||
$returnResponse = $controller->redirectAction($request, $route, $permanent, $ignoreAttributes, $keepRequestMethod); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to revert
5f3b11e
to
b6a2af3
Compare
This PR is rdy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with minor comments
{ | ||
if ('' == $route) { | ||
throw new HttpException($permanent ? 410 : 404); | ||
} | ||
|
||
$attributes = array(); | ||
if (false === $ignoreAttributes || is_array($ignoreAttributes)) { | ||
$attributes = $request->attributes->get('_route_params'); | ||
$routeParams = $request->attributes->get('_route_params'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest keeping the name $attributes, it's still valid and will reduce merge conflicts
on the next line, no need for the \
in front of array_merge
{ | ||
if ('' == $route) { | ||
throw new HttpException($permanent ? 410 : 404); | ||
} | ||
|
||
$attributes = array(); | ||
if (false === $ignoreAttributes || is_array($ignoreAttributes)) { | ||
$attributes = $request->attributes->get('_route_params'); | ||
$routeParams = $request->attributes->get('_route_params'); | ||
$attributes = $keepQueryParams ? \array_merge($request->query->all(), $routeParams) : $routeParams; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest adding a test ensuring that attributes coming from _route_params
still win over attributes coming from the query string when merging them together.
$request->query = new ParameterBag(array('base' => 'zaza')); | ||
$request->attributes = new ParameterBag(array('_route_params' => array())); | ||
$urlGenerator = $this->getMockBuilder(UrlGeneratorInterface::class)->getMock(); | ||
$urlGenerator->expects($this->any())->method('generate')->will($this->returnValue('/test?base=zaza')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does not test anything, as you don't assert arguments received by the router. Try to run your test on the unpatched codebase of the controller, and you will see that it will pass too.
@stof done. |
b6a2af3
to
406bfc9
Compare
Status: Needs Review |
Thank you @Simperfit. |
This PR was merged into the 4.1-dev branch. Discussion ---------- [FrameworkBundle] keep query in redirect | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | no | New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #26256 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | #9314 <!-- Write a short README entry for your feature/bugfix here (replace this comment block.) This will help people understand your PR and can be used as a start of the Doc PR. Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Commits ------- 406bfc9 [FrameworkBundle] keep query params in redirection