Skip to content

Commit

Permalink
Fixed relative redirects for ambiguous paths
Browse files Browse the repository at this point in the history
  • Loading branch information
pkruithof authored and fabpot committed Aug 5, 2014
1 parent 6094b5b commit 5ecc449
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/BrowserKit/Client.php
Expand Up @@ -303,7 +303,7 @@ public function request($method, $uri, array $parameters = array(), array $files

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

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

Expand Down
13 changes: 13 additions & 0 deletions src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Expand Up @@ -399,6 +399,19 @@ public function testFollowRedirect()
}
}

public function testFollowRelativeRedirect()
{
$client = new TestClient();
$client->setNextResponse(new Response('', 302, array('Location' => '/redirected')));
$client->request('GET', 'http://www.example.com/foo/foobar');
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows a redirect if any');

$client = new TestClient();
$client->setNextResponse(new Response('', 302, array('Location' => '/redirected:1234')));
$client->request('GET', 'http://www.example.com/foo/foobar');
$this->assertEquals('http://www.example.com/redirected:1234', $client->getRequest()->getUri(), '->followRedirect() follows relative urls');
}

public function testFollowRedirectWithMaxRedirects()
{
$client = new TestClient();
Expand Down

0 comments on commit 5ecc449

Please sign in to comment.