8000 [BrowserKit] Fixed the handling of parameters when redirecting · symfony/symfony@0e437c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e437c5

Browse files
committed
[BrowserKit] Fixed the handling of parameters when redirecting
POST parameters should not be transmitted as GET parameters after the redirection when changing the method.
1 parent 1fd8652 commit 0e437c5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,17 @@ public function followRedirect()
435435
$content = $request->getContent();
436436
}
437437

438+
if ('get' === strtolower($method)) {
439+
// Don't forward parameters for GET request as it should reach the redirection URI
440+
$parameters = array();
441+
} else {
442+
$parameters = $request->getParameters();
443+
}
444+
438445
$server = $request->getServer();
439446
unset($server['HTTP_IF_NONE_MATCH'], $server['HTTP_IF_MODIFIED_SINCE']);
440447

441-
return $this->request($method, $this->redirect, $request->getParameters(), $files, $server, $content);
448+
return $this->request($method, $this->redirect, $parameters, $files, $server, $content);
442449
}
443450

444451
/**

src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,10 @@ public function testFollowRedirect()
329329

330330
$client = new TestClient();
331331
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
332-
$client->request('POST', 'http://www.example.com/foo/foobar');
332+
$client->request('POST', 'http://www.example.com/foo/foobar', array('name' => 'bar'));
333333

334334
$this->assertEquals('get', $client->getRequest()->getMethod(), '->followRedirect() uses a get for 302');
335+
$this->assertEquals(array(), $client->getRequest()->getParameters(), '->followRedirect() does not submit parameters when changing the method');
335336
}
336337

337338
public function testFollowRedirectWithCookies()

0 commit comments

Comments
 (0)
0