Skip to content
Browse files

Updating Validation::url() with $strict parameter to require URL sche…

…me, fixes #5536

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7958 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
1 parent b2b46c3 commit 1deae7a586b072d7a75f4fc4dbe1133163e3408f @nateabele nateabele committed Dec 25, 2008
Showing with 4 additions and 2 deletions.
  1. +2 −2 cake/libs/validation.php
  2. +2 −0 cake/tests/cases/libs/validation.test.php
View
4 cake/libs/validation.php
@@ -801,11 +801,11 @@ function ssn($check, $regex = null, $country = null) {
* @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
2 cake/tests/cases/libs/validation.test.php
@@ -1656,6 +1656,8 @@ function testUrl() {
$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

0 comments on commit 1deae7a

Please sign in to comment.
Something went wrong with that request. Please try again.