Updating Validation::url() with $strict parameter to require URL scheme, fixes #5536

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7958 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-12-25 22:11:06 +00:00
parent b2b46c3fa4
commit 1deae7a586
2 changed files with 4 additions and 2 deletions

View file

@ -801,11 +801,11 @@ class Validation extends Object {
* @return boolean Success
* @access public
*/
function url($check) {
function url($check, $strict = false) {
$_this =& Validation::getInstance();
$_this->check = $check;
$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=') . '\/0-9a-z]|(%[0-9a-f]{2}))';
$_this->regex = '/^(?:(?:https?|ftps?|file|news|gopher):\/\/)?' .
$_this->regex = '/^(?:(?:https?|ftps?|file|news|gopher):\/\/)' . ife($strict, '', '?') .
'(?:' . $_this->__pattern['ip'] . '|' . $_this->__pattern['hostname'] . ')(?::[1-9][0-9]{0,3})?' .
'(?:\/?|\/' . $validChars . '*)?' .
'(?:\?' . $validChars . '*)?' .

View file

@ -1656,6 +1656,8 @@ class ValidationTestCase extends CakeTestCase {
$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/'));
$this->assertFalse(Validation::url('www.cakephp.org', true));
$this->assertTrue(Validation::url('http://www.cakephp.org', true));
}
/**
* testInList method