From ed2054f4f256aa1acfa448ef38e9a2a033c28c60 Mon Sep 17 00:00:00 2001 From: euromark Date: Sun, 13 Oct 2013 23:43:29 +0200 Subject: [PATCH] Allow international domains to pass validation. Fixes #1763 --- lib/Cake/Test/Case/Utility/ValidationTest.php | 8 +++++++- lib/Cake/Utility/Validation.php | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/ValidationTest.php b/lib/Cake/Test/Case/Utility/ValidationTest.php index 7838e713cd6..7c325c33322 100644 --- a/lib/Cake/Test/Case/Utility/ValidationTest.php +++ b/lib/Cake/Test/Case/Utility/ValidationTest.php @@ -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')); @@ -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')); } @@ -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')); diff --git a/lib/Cake/Utility/Validation.php b/lib/Cake/Utility/Validation.php index 9a803e5623f..f88e3636971 100644 --- a/lib/Cake/Utility/Validation.php +++ b/lib/Cake/Utility/Validation.php @@ -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,})' ); /** @@ -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) { @@ -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 . '*)?' .