Skip to content

Commit

Permalink
Allow international domains to pass validation. Fixes #1763
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Oct 13, 2013
1 parent ee0ed3a commit ed2054f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/Cake/Test/Case/Utility/ValidationTest.php
Expand Up @@ -1708,6 +1708,11 @@ public function testEmail() {
$this->assertTrue(Validation::email('!def!xyz%abc@example.com'));
$this->assertTrue(Validation::email('_somename@example.com'));

/// Unicode
$this->assertTrue(Validation::email('some@eräume.foo'));
$this->assertTrue(Validation::email('äu@öe.eräume.foo'));
$this->assertTrue(Validation::email('Nyrée.surname@example.com'));

// invalid addresses
$this->assertFalse(Validation::email('abc@example'));
$this->assertFalse(Validation::email('abc@example.c'));
Expand All @@ -1725,7 +1730,6 @@ public function testEmail() {
$this->assertFalse(Validation::email("abc@sub'example.com"));
$this->assertFalse(Validation::email('abc@sub/example.com'));
$this->assertFalse(Validation::email('abc@yahoo!.com'));
$this->assertFalse(Validation::email("Nyrée.surname@example.com"));
$this->assertFalse(Validation::email('abc@example_underscored.com'));
$this->assertFalse(Validation::email('raw@test.ra.ru....com'));
}
Expand Down Expand Up @@ -1904,6 +1908,8 @@ public function testUrl() {
$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://www.eräume.foo'));
$this->assertTrue(Validation::url('http://äüö.eräume.foo'));

$this->assertTrue(Validation::url('http://cakephp.org:80'));
$this->assertTrue(Validation::url('http://cakephp.org:443'));
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Utility/Validation.php
Expand Up @@ -39,7 +39,7 @@ class Validation {
* @var array
*/
protected static $_pattern = array(
'hostname' => '(?:[_a-z0-9][-_a-z0-9]*\.)*(?:[a-z0-9][-a-z0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,})'
'hostname' => '(?:[_\p{L}0-9][-_\p{L}0-9]*\.)*(?:[\p{L}0-9][-\p{L}0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,})'
);

/**
Expand Down Expand Up @@ -431,7 +431,7 @@ public static function email($check, $deep = false, $regex = null) {
}

if ($regex === null) {
$regex = '/^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@' . self::$_pattern['hostname'] . '$/i';
$regex = '/^[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]+)*@' . self::$_pattern['hostname'] . '$/ui';
}
$return = self::_check($check, $regex);
if ($deep === false || $deep === null) {
Expand Down Expand Up @@ -756,7 +756,7 @@ public static function ssn($check, $regex = null, $country = null) {
*/
public static function url($check, $strict = false) {
self::_populateIp();
$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~[]') . '\/0-9a-z\p{L}\p{N}]|(%[0-9a-f]{2}))';
$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~[]') . '\/0-9\p{L}\p{N}]|(%[0-9a-f]{2}))';
$regex = '/^(?:(?:https?|ftps?|sftp|file|news|gopher):\/\/)' . (!empty($strict) ? '' : '?') .
'(?:' . self::$_pattern['IPv4'] . '|\[' . self::$_pattern['IPv6'] . '\]|' . self::$_pattern['hostname'] . ')(?::[1-9][0-9]{0,4})?' .
'(?:\/?|\/' . $validChars . '*)?' .
Expand Down

0 comments on commit ed2054f

Please sign in to comment.