mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
updating documentation for url validation, making the regex easier to edit. Ref #5685
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7828 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
2a9b8643db
commit
b12a5739a2
2 changed files with 33 additions and 12 deletions
|
@ -825,7 +825,16 @@ class Validation extends Object {
|
|||
return $_this->_check();
|
||||
}
|
||||
/**
|
||||
* Checks that a value is a valid URL.
|
||||
* Checks that a value is a valid URL according to http://www.w3.org/Addressing/URL/url-spec.txt
|
||||
*
|
||||
* The regex checks for the following component parts:
|
||||
* a valid, optional, scheme
|
||||
* a valid ip address OR
|
||||
* a valid domain name as defined by section 2.3.1 of http://www.ietf.org/rfc/rfc1035.txt
|
||||
* with an optional port number
|
||||
* an optional valid path
|
||||
* an optional query string (get parameters)
|
||||
* an optional fragment (anchor tag)
|
||||
*
|
||||
* @param string $check Value to check
|
||||
* @return boolean Success
|
||||
|
@ -834,9 +843,16 @@ class Validation extends Object {
|
|||
function url($check) {
|
||||
$_this =& Validation::getInstance();
|
||||
$_this->check = $check;
|
||||
$_this->regex = '/^(?:(?:https?|ftps?|file|news|gopher):\\/\\/)?(?:(?:(?:25[0-5]|2[0-4]\d|(?:(?:1\d)?|[1-9]?)\d)\.){3}(?:25[0-5]|2[0-4]\d|(?:(?:1\d)?|[1-9]?)\d)'
|
||||
. '|(?:[0-9a-z]{1}[0-9a-z\\-]*\\.)*(?:[0-9a-z]{1}[0-9a-z\\-]{0,62})\\.(?:[a-z]{2,6}|[a-z]{2}\\.[a-z]{2,6})'
|
||||
. '(?::[0-9]{1,4})?)(?:\\/?|\\/[\\w\\-\\.,\'@?^=%&:;\/~\\+\(\)#]*[\\w\\-\\@?^=%&\/~\\+\(\)#])$/i';
|
||||
$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=') . '\/0-9a-z]|(%[0-9a-f]{2}))';
|
||||
$_this->regex = '/^(?:(?:https?|ftps?|file|news|gopher):\\/\\/)?' .
|
||||
'(?:' .
|
||||
'(?:(?:25[0-5]|2[0-4]\d|(?:(?:1\d)?|[1-9]?)\d)\.){3}(?:25[0-5]|2[0-4]\d|(?:(?:1\d)?|[1-9]?)\d)|' .
|
||||
'(?:[0-9a-z]{1}[0-9a-z\\-]*\\.)*(?:[0-9a-z]{1}[0-9a-z\\-]{0,62})\\.(?:[a-z]{2,6}|[a-z]{2}\\.[a-z]{2,6})' .
|
||||
'(?::[0-9]{1,4})?' .
|
||||
')' .
|
||||
'(?:\/?|\/' . $validChars . '*)?' .
|
||||
'(?:\?' . $validChars . '*)?' .
|
||||
'(?:#' . $validChars . '*)?$/i';
|
||||
return $_this->_check();
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -1644,6 +1644,11 @@ class ValidationTestCase extends CakeTestCase {
|
|||
$this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com'));
|
||||
$this->assertFalse(Validation::url('http://this-domain-is-too-loooooong-by-icann-rules-maximum-length-is-63.com'));
|
||||
$this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2'));
|
||||
$this->assertTrue(Validation::url('http://www.domain.com/blogs/parenth()eses.php'));
|
||||
$this->assertTrue(Validation::url('http://www.domain.com/index.php?get=params&get2=params'));
|
||||
$this->assertTrue(Validation::url('http://www.domain.com/ndex.php?get=params&get2=params#anchor'));
|
||||
$this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode'));
|
||||
$this->assertTrue(Validation::url('http://www.domain.com/real%20url%20encodeing'));
|
||||
$this->assertTrue(Validation::url('http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)'));
|
||||
$this->assertFalse(Validation::url('http://en.(wikipedia).org/'));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue