Merge pull request #2130 from dereuromark/master-unicode

Allow international domains to pass validation.

Fixes #1763
This commit is contained in:
Mark Story 2013-10-13 15:09:34 -07:00
commit 76e35ca446
2 changed files with 10 additions and 4 deletions

View file

@ -1708,6 +1708,11 @@ class ValidationTest extends CakeTestCase {
$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 @@ class ValidationTest extends CakeTestCase {
$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 @@ class ValidationTest extends CakeTestCase {
$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'));

View file

@ -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 @@ class Validation {
}
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 @@ class Validation {
*/
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 . '*)?' .