[HttpFoundation] IpUtils::checkIp4() should allow networks

This commit is contained in:
Ivan Kurnosov 2015-05-19 22:18:22 +12:00 committed by Fabien Potencier
parent af0e02c35e
commit 921ecff9e2
2 changed files with 7 additions and 0 deletions

View File

@ -62,6 +62,10 @@ class IpUtils
public static function checkIp4($requestIp, $ip)
{
if (false !== strpos($ip, '/')) {
if ('0.0.0.0/0' === $ip) {
return true;
}
list($address, $netmask) = explode('/', $ip, 2);
if ($netmask < 1 || $netmask > 32) {

View File

@ -34,6 +34,9 @@ class IpUtilsTest extends \PHPUnit_Framework_TestCase
array(true, '192.168.1.1', array('1.2.3.4/1', '192.168.1.0/24')),
array(true, '192.168.1.1', array('192.168.1.0/24', '1.2.3.4/1')),
array(false, '192.168.1.1', array('1.2.3.4/1', '4.3.2.1/1')),
array(true, '1.2.3.4', '0.0.0.0/0'),
array(false, '1.2.3.4', '256.256.256/0'),
array(false, '1.2.3.4', '192.168.1.0/0'),
);
}