From 479aefc438a071d5c7d9e2724f77d8740d57ee77 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 30 Nov 2012 22:11:57 -0500 Subject: [PATCH] Update TLD validation to accept gTLD variations The upcoming gTLD extensions will allow much more variety in TLD names. Loosen the validation to better accept different length TLDs. Fixes #3414 --- lib/Cake/Test/Case/Utility/ValidationTest.php | 8 ++++++-- lib/Cake/Utility/Validation.php | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/ValidationTest.php b/lib/Cake/Test/Case/Utility/ValidationTest.php index 22afee2c9..db9a27d94 100644 --- a/lib/Cake/Test/Case/Utility/ValidationTest.php +++ b/lib/Cake/Test/Case/Utility/ValidationTest.php @@ -1655,6 +1655,11 @@ class ValidationTest extends CakeTestCase { $this->assertTrue(Validation::email('abc@example.travel')); $this->assertTrue(Validation::email('someone@st.t-com.hr')); + // gTLD's + $this->assertTrue(Validation::email('example@host.local')); + $this->assertTrue(Validation::email('example@x.org')); + $this->assertTrue(Validation::email('example@host.xxx')); + // strange, but technically valid email addresses $this->assertTrue(Validation::email('S=postmaster/OU=rz/P=uni-frankfurt/A=d400/C=de@gateway.d400.de')); $this->assertTrue(Validation::email('customer/department=shipping@example.com')); @@ -1669,7 +1674,6 @@ class ValidationTest extends CakeTestCase { $this->assertFalse(Validation::email('abc.@example.com')); $this->assertFalse(Validation::email('abc@example..com')); $this->assertFalse(Validation::email('abc@example.com.a')); - $this->assertFalse(Validation::email('abc@example.toolong')); $this->assertFalse(Validation::email('abc;@example.com')); $this->assertFalse(Validation::email('abc@example.com;')); $this->assertFalse(Validation::email('abc@efg@example.com')); @@ -1839,11 +1843,11 @@ class ValidationTest extends CakeTestCase { $this->assertTrue(Validation::url('http://example.com/~userdir/')); $this->assertTrue(Validation::url('http://underscore_subdomain.example.org')); $this->assertTrue(Validation::url('http://_jabber._tcp.gmail.com')); + $this->assertTrue(Validation::url('http://www.domain.longttldnotallowed')); $this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake')); $this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake')); $this->assertFalse(Validation::url('http://w_w.domain.co_m')); $this->assertFalse(Validation::url('http://www.domain.12com')); - $this->assertFalse(Validation::url('http://www.domain.longttldnotallowed')); $this->assertFalse(Validation::url('http://www.-invaliddomain.tld')); $this->assertFalse(Validation::url('http://www.domain.-invalidtld')); $this->assertFalse(Validation::url('http://this-domain-is-too-loooooong-by-icann-rules-maximum-length-is-63.com')); diff --git a/lib/Cake/Utility/Validation.php b/lib/Cake/Utility/Validation.php index 43347e37d..875f1dd1e 100644 --- a/lib/Cake/Utility/Validation.php +++ b/lib/Cake/Utility/Validation.php @@ -38,7 +38,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,4}|museum|travel)' + 'hostname' => '(?:[-_a-z0-9][-_a-z0-9]*\.)*(?:[a-z0-9][-a-z0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,})' ); /**