Permalink
Browse files

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
  • Loading branch information...
1 parent 889c1eb commit 479aefc438a071d5c7d9e2724f77d8740d57ee77 @markstory markstory committed Dec 1, 2012
Showing with 7 additions and 3 deletions.
  1. +6 −2 lib/Cake/Test/Case/Utility/ValidationTest.php
  2. +1 −1 lib/Cake/Utility/Validation.php
@@ -1655,6 +1655,11 @@ public function testEmail() {
$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 @@ public function testEmail() {
$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 @@ public function testUrl() {
$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'));
@@ -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,})'
ceeram
ceeram Dec 1, 2012 Member

This makes email tests fail on expecting exceptions on long tlds, suppose we should change them to asserting no exception

lorenzo
lorenzo Dec 1, 2012 Owner

Already did :)

markstory
markstory Dec 2, 2012 Owner

If I missed one, let me know.

spiliot
spiliot Apr 30, 2013 Contributor

Apparently this regex allows --.example.com which is not a valid domain. Also localhost or main-machine can be used in intranents, shouldn't they be allowed?

Should I refine the regex to accept one or both cases above?

markstory
markstory Apr 30, 2013 Owner

localhost and main-machine seem reasonable, as they are valid hostnames, but --.example.com should be fixed 😄

spiliot
spiliot Apr 30, 2013 Contributor

Exactly what I meant but expressed in bad english 😄
I'll get down to it tomorrow, it's 4:30am here and my use of english is a sign I should be 😴

);
/**

0 comments on commit 479aefc

Please sign in to comment.