From 1deae7a586b072d7a75f4fc4dbe1133163e3408f Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 25 Dec 2008 22:11:06 +0000 Subject: [PATCH] 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 --- cake/libs/validation.php | 4 ++-- cake/tests/cases/libs/validation.test.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cake/libs/validation.php b/cake/libs/validation.php index 2b0b564e3..db9d003c3 100644 --- a/cake/libs/validation.php +++ b/cake/libs/validation.php @@ -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 . '*)?' . diff --git a/cake/tests/cases/libs/validation.test.php b/cake/tests/cases/libs/validation.test.php index c2e38b699..0c9495d63 100644 --- a/cake/tests/cases/libs/validation.test.php +++ b/cake/tests/cases/libs/validation.test.php @@ -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