From 0e437c59787202f1338278ca7f6161c1ab3276fb Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Mon, 16 Sep 2013 18:44:24 +0200 Subject: [PATCH] [BrowserKit] Fixed the handling of parameters when redirecting POST parameters should not be transmitted as GET parameters after the redirection when changing the method. --- src/Symfony/Component/BrowserKit/Client.php | 9 ++++++++- src/Symfony/Component/BrowserKit/Tests/ClientTest.php | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index 2c5dd26d5f..0b0f1e14f5 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -435,10 +435,17 @@ abstract class Client $content = $request->getContent(); } + if ('get' === strtolower($method)) { + // Don't forward parameters for GET request as it should reach the redirection URI + $parameters = array(); + } else { + $parameters = $request->getParameters(); + } + $server = $request->getServer(); unset($server['HTTP_IF_NONE_MATCH'], $server['HTTP_IF_MODIFIED_SINCE']); - return $this->request($method, $this->redirect, $request->getParameters(), $files, $server, $content); + return $this->request($method, $this->redirect, $parameters, $files, $server, $content); } /** diff --git a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php index 7c9d18d81a..2ed0dcdcf4 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php @@ -329,9 +329,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase $client = new TestClient(); $client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected'))); - $client->request('POST', 'http://www.example.com/foo/foobar'); + $client->request('POST', 'http://www.example.com/foo/foobar', array('name' => 'bar')); $this->assertEquals('get', $client->getRequest()->getMethod(), '->followRedirect() uses a get for 302'); + $this->assertEquals(array(), $client->getRequest()->getParameters(), '->followRedirect() does not submit parameters when changing the method'); } public function testFollowRedirectWithCookies()