merged branch neilferreira/master (PR #4472)
Commits -------85db221
Since getClientIp() no longer takes a parameter, removed that old test7b5328f
getClientIp() will now only return valid IP addresses, rather than assuming the X_FORWARDED_FOR is the first comma seperated value. Discussion ---------- getClientIp() will now only return valid IP addresses, rather than assuming the X_FORWARDED_FOR is the first comma seperated value. Fixes #4471 I'm not sure why an empty string was being returned in the first place, rather than null. Any ideas? --------------------------------------------------------------------------- by travisbot at 2012-05-31T08:59:12Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1485615) (merged 68c17e07 into78747e6c
). --------------------------------------------------------------------------- by travisbot at 2012-05-31T09:02:57Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1485634) (merged 9c1ba1c4 into78747e6c
). --------------------------------------------------------------------------- by neilferreira at 2012-05-31T09:04:16Z Sorted, I'm guessing I need to squash the commits? --------------------------------------------------------------------------- by travisbot at 2012-05-31T09:21:30Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1485732) (merged7b5328f1
into78747e6c
). --------------------------------------------------------------------------- by igorw at 2012-05-31T09:38:07Z With what value did it fail? Can you add a test case for that `HTTP_X_FORWARDED_FOR ` value? --------------------------------------------------------------------------- by neilferreira at 2012-05-31T10:45:11Z Anyone have any idea why that function returns an empty string instead of null ? --------------------------------------------------------------------------- by neilferreira at 2012-05-31T11:34:12Z @igorw done, I've also removed an old test that should have been removed when getClientIp() started using the 'trust proxy' variable concept. --------------------------------------------------------------------------- by travisbot at 2012-05-31T11:38:19Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1486534) (merged85db2213
into78747e6c
).
This commit is contained in:
commit
4d46da7d08
@ -546,9 +546,16 @@ class Request
|
||||
if ($this->server->has('HTTP_CLIENT_IP')) {
|
||||
return $this->server->get('HTTP_CLIENT_IP');
|
||||
} elseif ($this->server->has('HTTP_X_FORWARDED_FOR')) {
|
||||
$clientIp = explode(',', $this->server->get('HTTP_X_FORWARDED_FOR'), 2);
|
||||
$clientIp = explode(',', $this->server->get('HTTP_X_FORWARDED_FOR'));
|
||||
|
||||
return isset($clientIp[0]) ? trim($clientIp[0]) : '';
|
||||
foreach ($clientIp as $ipAddress) {
|
||||
$cleanIpAddress = trim($ipAddress);
|
||||
|
||||
if (false !== filter_var($cleanIpAddress, FILTER_VALIDATE_IP)) {
|
||||
return $cleanIpAddress;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -552,7 +552,6 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$request = new Request();
|
||||
$this->assertEquals('', $request->getClientIp());
|
||||
$this->assertEquals('', $request->getClientIp(true));
|
||||
|
||||
$server = array('REMOTE_ADDR' => $remoteAddr);
|
||||
if (null !== $httpClientIp) {
|
||||
@ -584,6 +583,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
||||
array('2620:0:1cfe:face:b00c::3', true, '::1', '2620:0:1cfe:face:b00c::3', null),
|
||||
array('2620:0:1cfe:face:b00c::3', true, '::1', null, '2620:0:1cfe:face:b00c::3, ::1'),
|
||||
array('88.88.88.88', true, '123.45.67.89', null, '88.88.88.88, 87.65.43.21, 127.0.0.1'),
|
||||
array('88.88.88.88', true, '123.45.67.89', null, 'unknown, 88.88.88.88'),
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user