8000 bug #10649 [BrowserKit] Fix #10641 : BrowserKit is broken when using … · symfony/symfony@9a95f52 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a95f52

Browse files
committed
bug #10649 [BrowserKit] Fix #10641 : BrowserKit is broken when using 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
2 parents a18ee42 + e946da3 commit 9a95f52

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public function request($method, $uri, array $parameters = array(), array $files
304304
$uri = $this->getAbsoluteUri($uri);
305305

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

310310
if (isset($server['HTTPS'])) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ public function testGetRequest()
103103
$this->assertEquals('http://example.com/', $client->getRequest()->getUri(), '->getCrawler() returns the Request of the last request');
104104
}
105105

106+
public function testGetRequestWithIpAsHost()
107+
{
108+
$client = new TestClient();
109+
$client->request('GET', 'https://example.com/foo', array(), array(), array('HTTP_HOST' => '127.0.0.1'));
110+
111+
$this->assertEquals('https://127.0.0.1/foo', $client->getRequest()->getUri());
112+
}
113+
106114
public function testGetResponse()
107115
{
108116
$client = new TestClient();

0 commit comments

Comments
 (0)
0