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

Merged
merged 1 commit into from Mar 27, 2018

Conversation

Projects
None yet
6 participants
@Simperfit
Contributor

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 changed the title from Feature/keep query in redirect to [FrameworkBundle] feature: keep query in redirect Feb 23, 2018

@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

This comment has been minimized.

@chalasr

chalasr Feb 23, 2018

Member

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

This comment has been minimized.

@chalasr

chalasr Feb 23, 2018

Member

to revert

@Simperfit

This comment has been minimized.

Contributor

Simperfit commented Mar 2, 2018

This PR is rdy.

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

@nicolas-grekas

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

This comment has been minimized.

@nicolas-grekas

nicolas-grekas Mar 19, 2018

Member

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;

This comment has been minimized.

@stof

stof Mar 19, 2018

Member

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

This comment has been minimized.

@stof

stof Mar 19, 2018

Member

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

This comment has been minimized.

Contributor

Simperfit commented Mar 26, 2018

@stof done.

@Simperfit

This comment has been minimized.

Contributor

Simperfit commented Mar 26, 2018

Status: Needs Review

@fabpot

fabpot approved these changes Mar 27, 2018

@fabpot

This comment has been minimized.

Member

fabpot commented Mar 27, 2018

Thank you @Simperfit.

@fabpot fabpot merged commit 406bfc9 into symfony:master Mar 27, 2018

2 of 3 checks passed

fabbot.io Doing some proofreading and checking your coding style.
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

fabpot added a commit that referenced this pull request Mar 27, 2018

feature #26281 [FrameworkBundle] keep query in redirect (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

@Simperfit Simperfit deleted the Simperfit:feature/keep-query-in-redirect branch Mar 27, 2018

@fabpot fabpot referenced this pull request May 7, 2018

Merged

Release v4.1.0-BETA1 #27181

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment