Skip to content

Commit 3c5a863

Browse files
committed
bug #9447 [BrowserKit] fixed protocol-relative url redirection (jong99)
This PR was merged into the 2.2 branch. Discussion ---------- [BrowserKit] fixed protocol-relative url redirection Fixed redirects to protocol relative URLs, e.g. //www.example.org. Previously the code would treat this as a relative URL. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #9445 | License | MIT | Doc PR | Commits ------- e8b5c84 bug #9445 [BrowserKit] fixed protocol-relative url redirection
2 parents ccf0575 + e8b5c84 commit 3c5a863

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,11 @@ protected function getAbsoluteUri($uri)
484484
);
485485
}
486486

487+
// protocol relative URL
488+
if (0 === strpos($uri, '//')) {
489+
return parse_url($currentUri, PHP_URL_SCHEME).':'.$uri;
490+
}
491+
487492
// anchor?
488493
if (!$uri || '#' == $uri[0]) {
489494
return preg_replace('/#.*?$/', '', $currentUri).$uri;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,18 @@ public function testFollowRedirect()
327327

328328
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() automatically follows redirects if followRedirects is true');
329329

330+
$client = new TestClient();
331+
$client->setNextResponse(new Response('', 302, array('Location' => '/redirected')));
332+
$client->request('GET', 'http://www.example.com/foo/foobar');
333+
334+
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows relative URLs');
335+
336+
$client = new TestClient();
337+
$client->setNextResponse(new Response('', 302, array('Location' => '//www.example.org/')));
338+
$client->request('GET', 'https://www.example.com/');
339+
340+
$this->assertEquals('https://www.example.org/', $client->getRequest()->getUri(), '->followRedirect() follows protocol-relative URLs');
341+
330342
$client = new TestClient();
331343
$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
332344
$client->request('POST', 'http://www.example.com/foo/foobar', array('name' => 'bar'));

0 commit comments

Comments
 (0)