Browse files

Adding [ and ] to the list of allowed characters in validation::url()

This matches the behavior of PHP's filter_var()
Fixes #1717
  • Loading branch information...
1 parent efbb647 commit 04948762175f855a460cb1fc5ef6ddd05a430cd2 @markstory markstory committed May 20, 2011
Showing with 2 additions and 1 deletion.
  1. +1 −1 cake/libs/validation.php
  2. +1 −0 cake/tests/cases/libs/validation.test.php
View
2 cake/libs/validation.php
@@ -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})?' .
View
1 cake/tests/cases/libs/validation.test.php
@@ -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'));

0 comments on commit 0494876

Please sign in to comment.