Skip to content

Commit

Permalink
Fixing validation errors for wrong case checking on Validation::ip.
Browse files Browse the repository at this point in the history
Adding IPv6 validation for Validation::url().
Added tests for ports in urls.
Fixed port length allowance on Validation.
  • Loading branch information
predominant committed Jan 7, 2010
1 parent 485570d commit e2a2770
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cake/libs/validation.php
Expand Up @@ -556,6 +556,7 @@ function extension($check, $extensions = array('gif', 'jpeg', 'png', 'jpg')) {
function ip($check, $type = 'both') {
$_this =& Validation::getInstance();
$success = false;
$type = strtolower($type);
if ($type === 'ipv4' || $type === 'both') {
$success |= $_this->_ipv4($check);
}
Expand Down Expand Up @@ -856,7 +857,8 @@ function url($check, $strict = false) {
$_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';
Expand Down
17 changes: 17 additions & 0 deletions cake/tests/cases/libs/validation.test.php
Expand Up @@ -1876,6 +1876,23 @@ function testUrl() {
$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]'));
}

/**
Expand Down

0 comments on commit e2a2770

Please sign in to comment.