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:
Fabien Potencier 2014-06-18 07:53:47 +02:00
commit fbf92e58cb
2 changed files with 15 additions and 1 deletions

View File

@ -932,7 +932,13 @@ class Request
}
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));
}

View File

@ -163,6 +163,14 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(90, $request->getPort());
$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"]}';
$request = Request::create('http://example.com/jsonrpc', 'POST', array(), array(), array(), array(), $json);
$this->assertEquals($json, $request->getContent());