Skip to content

Commit

Permalink
[BrowserKit] Fixed the handling of parameters when redirecting
Browse files Browse the repository at this point in the history
POST parameters should not be transmitted as GET parameters after the
redirection when changing the method.
  • Loading branch information
stof committed Sep 16, 2013
1 parent 1fd8652 commit 0e437c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Symfony/Component/BrowserKit/Client.php
Expand Up @@ -435,10 +435,17 @@ public function followRedirect()
$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);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Expand Up @@ -329,9 +329,10 @@ public function testFollowRedirect()

$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()
Expand Down

0 comments on commit 0e437c5

Please sign in to comment.