Skip to content

Commit

Permalink
bug #9447 [BrowserKit] fixed protocol-relative url redirection (jong99)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabpot committed Nov 22, 2013
2 parents ccf0575 + e8b5c84 commit 3c5a863
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/BrowserKit/Client.php
Expand Up @@ -484,6 +484,11 @@ protected function getAbsoluteUri($uri)
);
}

// protocol relative URL
if (0 === strpos($uri, '//')) {
return parse_url($currentUri, PHP_URL_SCHEME).':'.$uri;
}

// anchor?
if (!$uri || '#' == $uri[0]) {
return preg_replace('/#.*?$/', '', $currentUri).$uri;
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Expand Up @@ -327,6 +327,18 @@ public function testFollowRedirect()

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

$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 relative URLs');

$client = new TestClient();
$client->setNextResponse(new Response('', 302, array('Location' => '//www.example.org/')));
$client->request('GET', 'https://www.example.com/');

$this->assertEquals('https://www.example.org/', $client->getRequest()->getUri(), '->followRedirect() follows protocol-relative URLs');

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

0 comments on commit 3c5a863

Please sign in to comment.