Skip to content

Commit

Permalink
Adding [ and ] to the list of allowed characters in validation::url()
Browse files Browse the repository at this point in the history
This matches the behavior of PHP's filter_var()
Fixes #1717
  • Loading branch information
markstory committed May 21, 2011
1 parent efbb647 commit 0494876
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/libs/validation.php
Expand Up @@ -874,7 +874,7 @@ function url($check, $strict = false) {
$_this =& Validation::getInstance();
$_this->__populateIp();
$_this->check = $check;
$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~') . '\/0-9a-z\p{L}\p{N}]|(%[0-9a-f]{2}))';
$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~[]') . '\/0-9a-z\p{L}\p{N}]|(%[0-9a-f]{2}))';
$_this->regex = '/^(?:(?:https?|ftps?|file|news|gopher):\/\/)' . (!empty($strict) ? '' : '?') .
'(?:' . $_this->__pattern['IPv4'] . '|\[' . $_this->__pattern['IPv6'] . '\]|' . $_this->__pattern['hostname'] . ')' .
'(?::[1-9][0-9]{0,4})?' .
Expand Down
1 change: 1 addition & 0 deletions cake/tests/cases/libs/validation.test.php
Expand Up @@ -1880,6 +1880,7 @@ function testUrl() {
$this->assertTrue(Validation::url('http://www.zwischenraume.de'));
$this->assertTrue(Validation::url('http://www.zwischenraume.cz'));
$this->assertTrue(Validation::url('http://www.last.fm/music/浜崎あゆみ'), 'utf8 path failed');
$this->assertTrue(Validation::url('http://www.electrohome.ro/images/239537750-284232-215_300[1].jpg'));

$this->assertTrue(Validation::url('http://cakephp.org:80'));
$this->assertTrue(Validation::url('http://cakephp.org:443'));
Expand Down

0 comments on commit 0494876

Please sign in to comment.