bug #11144 [HttpFoundation] Fixed Request::getPort returns incorrect value under IPv6 (kicken)
This PR was merged into the 2.3 branch.
Discussion
----------
[HttpFoundation] Fixed Request::getPort returns incorrect value under IPv6
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Commits
-------
2a0e8e3
[HttpFoundation] Fixed Request::getPort returns incorrect value under IPv6
This commit is contained in:
commit
fbf92e58cb
@ -932,7 +932,13 @@ class Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($host = $this->headers->get('HOST')) {
|
if ($host = $this->headers->get('HOST')) {
|
||||||
if (false !== $pos = strrpos($host, ':')) {
|
if ($host[0] === '[') {
|
||||||
|
$pos = strpos($host, ':', strrpos($host, ']'));
|
||||||
|
} else {
|
||||||
|
$pos = strrpos($host, ':');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false !== $pos) {
|
||||||
return intval(substr($host, $pos + 1));
|
return intval(substr($host, $pos + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,6 +163,14 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(90, $request->getPort());
|
$this->assertEquals(90, $request->getPort());
|
||||||
$this->assertTrue($request->isSecure());
|
$this->assertTrue($request->isSecure());
|
||||||
|
|
||||||
|
$request = Request::create('https://[::1]/foo');
|
||||||
|
$this->assertEquals('https://[::1]/foo', $request->getUri());
|
||||||
|
$this->assertEquals('/foo', $request->getPathInfo());
|
||||||
|
$this->assertEquals('[::1]', $request->getHost());
|
||||||
|
$this->assertEquals('[::1]', $request->getHttpHost());
|
||||||
|
$this->assertEquals(443, $request->getPort());
|
||||||
|
$this->assertTrue($request->isSecure());
|
||||||
|
|
||||||
$json = '{"jsonrpc":"2.0","method":"echo","id":7,"params":["Hello World"]}';
|
$json = '{"jsonrpc":"2.0","method":"echo","id":7,"params":["Hello World"]}';
|
||||||
$request = Request::create('http://example.com/jsonrpc', 'POST', array(), array(), array(), array(), $json);
|
$request = Request::create('http://example.com/jsonrpc', 'POST', array(), array(), array(), array(), $json);
|
||||||
$this->assertEquals($json, $request->getContent());
|
$this->assertEquals($json, $request->getContent());
|
||||||
|
Reference in New Issue
Block a user