Skip to content
This repository
Browse code

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...
commit 04948762175f855a460cb1fc5ef6ddd05a430cd2 1 parent efbb647
Mark Story authored May 20, 2011
2  cake/libs/validation.php
@@ -874,7 +874,7 @@ function url($check, $strict = false) {
874 874
 		$_this =& Validation::getInstance();
875 875
 		$_this->__populateIp();
876 876
 		$_this->check = $check;
877  
-		$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~') . '\/0-9a-z\p{L}\p{N}]|(%[0-9a-f]{2}))';
  877
+		$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~[]') . '\/0-9a-z\p{L}\p{N}]|(%[0-9a-f]{2}))';
878 878
 		$_this->regex = '/^(?:(?:https?|ftps?|file|news|gopher):\/\/)' . (!empty($strict) ? '' : '?') .
879 879
 			'(?:' . $_this->__pattern['IPv4'] . '|\[' . $_this->__pattern['IPv6'] . '\]|' . $_this->__pattern['hostname'] . ')' .
880 880
 			'(?::[1-9][0-9]{0,4})?' .
1  cake/tests/cases/libs/validation.test.php
@@ -1880,6 +1880,7 @@ function testUrl() {
1880 1880
 		$this->assertTrue(Validation::url('http://www.zwischenraume.de'));
1881 1881
 		$this->assertTrue(Validation::url('http://www.zwischenraume.cz'));
1882 1882
 		$this->assertTrue(Validation::url('http://www.last.fm/music/浜崎あゆみ'), 'utf8 path failed');
  1883
+		$this->assertTrue(Validation::url('http://www.electrohome.ro/images/239537750-284232-215_300[1].jpg'));
1883 1884
 
1884 1885
 		$this->assertTrue(Validation::url('http://cakephp.org:80'));
1885 1886
 		$this->assertTrue(Validation::url('http://cakephp.org:443'));

0 notes on commit 0494876

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