Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Post/Redirect/Get should keep query parameters #5861

Merged
merged 1 commit into from

4 participants

campersau Matthew Weier O'Phinney Evan Coury Marco Pivetta
campersau

The Post Redirect Get Plugin should keep query parameters for redirects but I don't know if this is the right approach to do this.

Matthew Weier O'Phinney

@campersau yes, looks good -- and your test proves it! :)

Matthew Weier O'Phinney weierophinney added this to the 2.2.6 milestone
Evan Coury
Collaborator

I'd have to agree, it probably should have done this from the beginning, however, I'm slightly concerned this could be a BC break, as this would change the default behavior of the plugin slightly.

I'm not saying they should, but if anyone who is using the prg plugin sets query parameters on their form action, but is, for any reason, relying on those parameters not being present after the redirect, this could possibly present an issue.

So we should either, A) acknowledge that this likely affects so few users (none?) that it's not worth worrying about, or B) perhaps add a third parameter to the __invoke() method to toggle this option, and default it to off so that behavior doesn't change.

Marco Pivetta
Collaborator

@EvanDotPro a breakage here seems ok as long as it is documented. Manually redirecting is always possible anyway.

Evan Coury
Collaborator

@Ocramius fine by me. :)

Evan Coury
Collaborator

Corrected the title of this PR from Post/Request/Get to Post/Redirect/Get.

Evan Coury EvanDotPro self-assigned this
Evan Coury EvanDotPro merged commit 502a522 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 23, 2014
  1. campersau
This page is out of date. Refresh to see the latest.
2  library/Zend/Mvc/Controller/Plugin/PostRedirectGet.php
View
@@ -95,7 +95,7 @@ protected function redirect($redirect, $redirectToUrl)
{
$controller = $this->getController();
$params = array();
- $options = array();
+ $options = array('query' => $controller->params()->fromQuery());
$reuseMatchedParams = false;
if (null === $redirect) {
27 tests/ZendTest/Mvc/Controller/Plugin/PostRedirectGetTest.php
View
@@ -18,6 +18,7 @@
use Zend\Mvc\Router\Http\Segment as SegmentRoute;
use Zend\Mvc\Router\RouteMatch;
use Zend\Mvc\Router\SimpleRouteStack;
+use Zend\Mvc\Router\Http\TreeRouteStack;
use Zend\Mvc\ModuleRouteListener;
use Zend\Stdlib\Parameters;
use ZendTest\Mvc\Controller\TestAsset\SampleController;
@@ -32,7 +33,7 @@ class PostRedirectGetTest extends TestCase
public function setUp()
{
- $router = new SimpleRouteStack;
+ $router = new TreeRouteStack;
$router->addRoute('home', LiteralRoute::factory(array(
'route' => '/',
'defaults' => array(
@@ -219,4 +220,28 @@ public function testReuseMatchedParametersWithSegmentController()
$this->assertEquals($expects, $prgResultRoute->getHeaders()->get('Location')->getUri() , 'expects to redirect for the same url');
$this->assertEquals(303, $prgResultRoute->getStatusCode());
}
+
+ public function testKeepUrlQueryParameters()
+ {
+ $expects = '/ctl/sample';
+ $this->request->setMethod('POST');
+ $this->request->setUri($expects);
+ $this->request->setQuery(new Parameters(array(
+ 'id' => '123',
+ )));
+
+ $routeMatch = $this->event->getRouter()->match($this->request);
+ $this->event->setRouteMatch($routeMatch);
+
+ $moduleRouteListener = new ModuleRouteListener;
+ $moduleRouteListener->onRoute($this->event);
+
+ $this->controller->dispatch($this->request, $this->response);
+ $prgResultRoute = $this->controller->prg();
+
+ $this->assertInstanceOf('Zend\Http\Response', $prgResultRoute);
+ $this->assertTrue($prgResultRoute->getHeaders()->has('Location'));
+ $this->assertEquals($expects . '?id=123', $prgResultRoute->getHeaders()->get('Location')->getUri() , 'expects to redirect for the same url');
+ $this->assertEquals(303, $prgResultRoute->getStatusCode());
+ }
}
Something went wrong with that request. Please try again.