-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[BrowserKit] Fixed server HTTP_HOST port uri conversion #11356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The issue is that you specify |
hmm, actually, it does include it. It is SERVER_NAME which does not include it. |
So this means this commit should be reverted? We stumbled upon this error using goutte`s history functions:
|
Any news here, or anything I can help to get this merged? |
@@ -304,7 +304,15 @@ 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); | |||
if ($port = parse_url($uri, PHP_URL_PORT)) { | |||
$port = ':' . $port; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the spaces around the dot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
👍 |
1 similar comment
👍 |
$port = ':'.$port; | ||
} | ||
|
||
$uri = preg_replace('{^(https?\://)'.parse_url($uri, PHP_URL_HOST).$port.'}', '${1}'.$server['HTTP_HOST'], $uri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a preg_quote is required around parse_url($uri, PHP_URL_HOST).$port
, because:
var_dump(parse_url('abc.+def:9090', PHP_URL_HOST));
string(8) "abc.+def"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolas-grekas
I'm not sure if I can follow you.
You propose to change the code to:
if ($port = parse_url($uri, PHP_URL_PORT)) {
$port = ':'.$port;
}
$uri = preg_replace('{^(https?\://)'.preg_quote(parse_url($uri, PHP_URL_HOST).$port).'}', '${1}'.$server['HTTP_HOST'], $uri);
May you please provide me with a failing testcase like the following so I can verify the problem?
$client = new TestClient();
$server = array('HTTP_HOST' => 'www.example.com:8000');
$parameters = array();
$files = array();
$client->request('GET', 'http://example.com', $parameters, $files, $server);
$this->assertEquals('http://www.example.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST to add port');
Closing in favor of #11469 |
…cremer, fabpot) This PR was merged into the 2.3 branch. Discussion ---------- [BrowserKit] Fixed server HTTP_HOST port uri conversion | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11356 | License | MIT | Doc PR | n/a See #11356 Commits ------- 103fd88 [BrowserKit] refactor code and fix unquoted regex f401ab9 Fixed server HTTP_HOST port uri conversion
This will fix URI conversion using the HTTP_HOST server header.
Steps to reproduce:
We discovered this issue during mink testing using goutte on a non standard port.