merged branch hason/ipv6matcher (PR #5078)
Commits
-------
b384c82
[HttpFoundation] Fixed checking IPv6 address without bit-length of the prefix
Discussion
----------
[HttpFoundation] Fixed checking IPv6 address without bit-length of the p...
...refix
Replaces #5031
This commit is contained in:
commit
b6954e7f0b
@ -202,7 +202,16 @@ class RequestMatcher implements RequestMatcherInterface
|
||||
throw new \RuntimeException('Unable to check Ipv6. Check that PHP was not compiled with option "disable-ipv6".');
|
||||
}
|
||||
|
||||
list($address, $netmask) = explode('/', $ip, 2);
|
||||
if (false !== strpos($ip, '/')) {
|
||||
list($address, $netmask) = explode('/', $ip, 2);
|
||||
|
||||
if ($netmask < 1 || $netmask > 128) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$address = $ip;
|
||||
$netmask = 128;
|
||||
}
|
||||
|
||||
$bytesAddr = unpack("n*", inet_pton($address));
|
||||
$bytesTest = unpack("n*", inet_pton($requestIp));
|
||||
|
@ -62,6 +62,9 @@ class RequestMatcherTest extends \PHPUnit_Framework_TestCase
|
||||
return array(
|
||||
array(true, '2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'),
|
||||
array(false, '2a00:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'),
|
||||
array(false, '2a01:198:603:0:396e:4789:8e99:890f', '::1'),
|
||||
array(true, '0:0:0:0:0:0:0:1', '::1'),
|
||||
array(false, '0:0:603:0:396e:4789:8e99:0001', '::1'),
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user