Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
Mar 27, 2018

Conversation

Simperfit
Copy link
Contributor

@Simperfit Simperfit commented Feb 23, 2018

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

@Simperfit Simperfit force-pushed the feature/keep-query-in-redirect branch from c8c18f2 to a400739 Compare February 23, 2018 09:47
@Simperfit Simperfit changed the title Feature/keep query in redirect [FrameworkBundle] feature: keep query in redirect Feb 23, 2018
@Simperfit Simperfit force-pushed the feature/keep-query-in-redirect branch 3 times, most recently from 5fe9639 to 5f3b11e Compare February 23, 2018 09:55
@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Feb 23, 2018
* @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
Copy link
Member

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);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to revert

@Simperfit Simperfit force-pushed the feature/keep-query-in-redirect branch from 5f3b11e to b6a2af3 Compare February 23, 2018 13:47
@Simperfit
Copy link
Contributor Author

This PR is rdy.

@nicolas-grekas nicolas-grekas changed the title [FrameworkBundle] feature: keep query in redirect [FrameworkBundle] keep query in redirect Mar 19, 2018
Copy link
Member

@nicolas-grekas nicolas-grekas left a 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');
Copy link
Member

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;
Copy link
Member

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'));
Copy link
Member

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.

@Simperfit
Copy link
Contributor Author

@stof done.

@Simperfit Simperfit force-pushed the feature/keep-query-in-redirect branch from b6a2af3 to 406bfc9 Compare March 26, 2018 14:59
@Simperfit
Copy link
Contributor Author

Status: Needs Review

@fabpot
Copy link
Member

fabpot commented Mar 27, 2018

Thank you @Simperfit.

@fabpot fabpot merged commit 406bfc9 into symfony:master Mar 27, 2018
fabpot added a commit that referenced this pull request Mar 27, 2018
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
@Simperfit Simperfit deleted the feature/keep-query-in-redirect branch March 27, 2018 07:48
@fabpot fabpot mentioned this pull request May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants