Permalink
Browse files

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.
  • Loading branch information...
1 parent 485570d commit e2a2770d9f4c8f235c5e98d5c455b5f2abc727b6 @predominant predominant committed Jan 7, 2010
Showing with 20 additions and 1 deletion.
  1. +3 −1 cake/libs/validation.php
  2. +17 −0 cake/tests/cases/libs/validation.test.php
View
@@ -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);
}
@@ -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';
@@ -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]'));
}
/**

0 comments on commit e2a2770

Please sign in to comment.