Fixing validation errors for wrong case checking on Validation::ip.

Adding IPv6 validation for Validation::url().
Added tests for ports in urls.
Fixed port length allowance on Validation.
This commit is contained in:
predominant 2010-01-07 11:02:05 +11:00
parent 485570de24
commit e2a2770d9f
2 changed files with 20 additions and 1 deletions

View file

@ -556,6 +556,7 @@ class Validation extends Object {
function ip($check, $type = 'both') {
$_this =& Validation::getInstance();
$success = false;
$type = strtolower($type);
if ($type === 'ipv4' || $type === 'both') {
$success |= $_this->_ipv4($check);
}
@ -856,7 +857,8 @@ class Validation extends Object {
$_this->check = $check;
$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~') . '\/0-9a-z]|(%[0-9a-f]{2}))';
$_this->regex = '/^(?:(?:https?|ftps?|file|news|gopher):\/\/)' . (!empty($strict) ? '' : '?') .
'(?:' . $_this->__pattern['IPv4'] . '|' . $_this->__pattern['hostname'] . ')(?::[1-9][0-9]{0,3})?' .
'(?:' . $_this->__pattern['IPv4'] . '|\[' . $_this->__pattern['IPv6'] . '\]|' . $_this->__pattern['hostname'] . ')' .
'(?::[1-9][0-9]{0,4})?' .
'(?:\/?|\/' . $validChars . '*)?' .
'(?:\?' . $validChars . '*)?' .
'(?:#' . $validChars . '*)?$/i';

View file

@ -1876,6 +1876,23 @@ class ValidationTest extends CakeTestCase {
$this->assertFalse(Validation::url('www.cakephp.org', true));
$this->assertTrue(Validation::url('http://www.cakephp.org', true));
$this->assertTrue(Validation::url('http://example.com/~userdir/'));
$this->assertTrue(Validation::url('http://cakephp.org:80'));
$this->assertTrue(Validation::url('http://cakephp.org:443'));
$this->assertTrue(Validation::url('http://cakephp.org:2000'));
$this->assertTrue(Validation::url('http://cakephp.org:27000'));
$this->assertTrue(Validation::url('http://cakephp.org:65000'));
$this->assertTrue(Validation::url('[2001:0db8::1428:57ab]'));
$this->assertTrue(Validation::url('[::1]'));
$this->assertTrue(Validation::url('[2001:0db8::1428:57ab]:80'));
$this->assertTrue(Validation::url('[::1]:80'));
$this->assertTrue(Validation::url('http://[2001:0db8::1428:57ab]'));
$this->assertTrue(Validation::url('http://[::1]'));
$this->assertTrue(Validation::url('http://[2001:0db8::1428:57ab]:80'));
$this->assertTrue(Validation::url('http://[::1]:80'));
$this->assertFalse(Validation::url('[1::2::3]'));
}
/**