Skip to content

Commit

Permalink
bug #10649 [BrowserKit] Fix #10641 : BrowserKit is broken when using …
Browse files Browse the repository at this point in the history
…ip as host (romainneutron)

This PR was merged into the 2.3 branch.

Discussion
----------

[BrowserKit] Fix #10641 : BrowserKit is broken when using ip as host

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10641
| License       | MIT

As documented in http://php.net/manual/en/function.preg-replace.php, we have to use the `$` notation for replacing the backreference

>When working with a replacement pattern where a backreference is immediately followed by another number (i.e.: placing a literal number immediately after a matched pattern), you cannot use the familiar \\1 notation for your backreference. \\11, for example, would confuse preg_replace() since it does not know whether you want the \\1 backreference followed by a literal 1, or the \\11 backreference followed by nothing. In this case the solution is to use \${1}1. This creates an isolated $1 backreference, leaving the 1 as a literal.

Commits
-------

e946da3 [BrowserKit] Fix #10641 : BrowserKit is broken when using ip as host
  • Loading branch information
fabpot committed Apr 9, 2014
2 parents a18ee42 + e946da3 commit 9a95f52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/BrowserKit/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public function request($method, $uri, array $parameters = array(), array $files
$uri = $this->getAbsoluteUri($uri);

if (isset($server['HTTP_HOST'])) {
$uri = preg_replace('{^(https?\://)'.parse_url($uri, PHP_URL_HOST).'}', '\\1'.$server['HTTP_HOST'], $uri);
$uri = preg_replace('{^(https?\://)'.parse_url($uri, PHP_URL_HOST).'}', '${1}'.$server['HTTP_HOST'], $uri);
}

if (isset($server['HTTPS'])) {
Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ public function testGetRequest()
$this->assertEquals('http://example.com/', $client->getRequest()->getUri(), '->getCrawler() returns the Request of the last request');
}

public function testGetRequestWithIpAsHost()
{
$client = new TestClient();
$client->request('GET', 'https://example.com/foo', array(), array(), array('HTTP_HOST' => '127.0.0.1'));

$this->assertEquals('https://127.0.0.1/foo', $client->getRequest()->getUri());
}

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

0 comments on commit 9a95f52

Please sign in to comment.