From 5ecc4498987649a0539593217172be108ca6c447 Mon Sep 17 00:00:00 2001 From: Peter Kruithof Date: Mon, 28 Jul 2014 16:33:49 +0200 Subject: [PATCH] Fixed relative redirects for ambiguous paths --- src/Symfony/Component/BrowserKit/Client.php | 2 +- .../Component/BrowserKit/Tests/ClientTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index 08979f65a3..898c934296 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -303,7 +303,7 @@ abstract class Client $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); } diff --git a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php index 97205bf911..39015d2cc5 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php @@ -399,6 +399,19 @@ class ClientTest extends \PHPUnit_Framework_TestCase } } + 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();