8000 Fixed relative redirects for ambiguous paths · symfony/symfony@5ecc449 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ecc449

Browse files
pkruithoffabpot
authored andcommitted
Fixed relative redirects for ambiguous paths
1 parent 6094b5b commit 5ecc449

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public function request($method, $uri, array $parameters = array(), array $files
303303

304304
$uri = $this->getAbsoluteUri($uri);
305305

306-
if (isset($server['HTTP_HOST'])) {
306+
if (!empty($server['HTTP_HOST'])) {
307307
$uri = preg_replace('{^(https?\://)'.preg_quote($this->extractHost($uri)).'}', '${1}'.$server['HTTP_HOST'], $uri);
308308
}
309309

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,19 @@ public function testFollowRedirect()
399399
}
400400
}
401401

402+
public function testFollowRelativeRedirect()
403+
{
404+
$client = new TestClient();
405+
$client->setNextResponse(new Response('', 302, array('Location' => '/redirected')));
406+
$client->request('GET', 'http://www.example.com/foo/foobar');
407+
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows a redirect if any');
408+
409+
$client = new TestClient();
410+
$client->setNextResponse(new Response('', 302, array('Location' => '/redirected:1234')));
411+
$client->request('GET', 'http://www.example.com/foo/foobar');
412+
$this->assertEquals('http://www.example.com/redirected:1234', $client->getRequest()->getUri(), '->followRedirect() follows relative urls');
413+
}
414+
402415
public function testFollowRedirectWithMaxRedirects()
403416
{
404417
$client = new TestClient();

0 commit comments

Comments
 (0)
0