mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix Validation::ip() not respecting type.
Apply patch from 'Xavier Franquet' to fix ip(), so that it does not always validate both IP versions. Fixes #2944
This commit is contained in:
parent
56b2b8a8da
commit
454fae9bd0
2 changed files with 5 additions and 3 deletions
|
@ -1663,6 +1663,7 @@ class ValidationTest extends CakeTestCase {
|
|||
$this->assertFalse(Validation::ip('127.0.0'));
|
||||
$this->assertFalse(Validation::ip('127.0.0.a'));
|
||||
$this->assertFalse(Validation::ip('127.0.0.256'));
|
||||
$this->assertFalse(Validation::ip('2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'ipv4'), 'IPv6 is not valid IPv4');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1702,6 +1703,7 @@ class ValidationTest extends CakeTestCase {
|
|||
$this->assertFalse(Validation::ip('1:2:3::4:5:6:7:8:9', 'IPv6'));
|
||||
$this->assertFalse(Validation::ip('::ffff:2.3.4', 'IPv6'));
|
||||
$this->assertFalse(Validation::ip('::ffff:257.1.2.3', 'IPv6'));
|
||||
$this->assertFalse(Validation::ip('255.255.255.255', 'ipv6'), 'IPv4 is not valid IPv6');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -467,12 +467,12 @@ class Validation {
|
|||
*/
|
||||
public static function ip($check, $type = 'both') {
|
||||
$type = strtolower($type);
|
||||
$flags = array();
|
||||
$flags = null;
|
||||
if ($type === 'ipv4' || $type === 'both') {
|
||||
$flags[] = FILTER_FLAG_IPV4;
|
||||
$flags |= FILTER_FLAG_IPV4;
|
||||
}
|
||||
if ($type === 'ipv6' || $type === 'both') {
|
||||
$flags[] = FILTER_FLAG_IPV6;
|
||||
$flags |= FILTER_FLAG_IPV6;
|
||||
}
|
||||
return (boolean)filter_var($check, FILTER_VALIDATE_IP, array('flags' => $flags));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue