Browse Source

Merge pull request #722 from uzyn/bugfix/url-validation

Fix URL validation to allow underscores in subdomain.
Mark Story 13 years ago
parent
commit
f65b52bf11
2 changed files with 5 additions and 1 deletions
  1. 4 0
      lib/Cake/Test/Case/Utility/ValidationTest.php
  2. 1 1
      lib/Cake/Utility/Validation.php

+ 4 - 0
lib/Cake/Test/Case/Utility/ValidationTest.php

@@ -1782,6 +1782,10 @@ class ValidationTest extends CakeTestCase {
 		$this->assertFalse(Validation::url('www.cakephp.org', true));
 		$this->assertTrue(Validation::url('http://www.cakephp.org', true));
 		$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->assertFalse(Validation::url('http://www.underscore_domain.org'));
+		$this->assertFalse(Validation::url('http://_jabber._tcp.g_mail.com'));		
 
 		$this->assertTrue(Validation::url('http://example.com/~userdir/subdir/index.html'));
 		$this->assertTrue(Validation::url('http://www.zwischenraume.de'));

+ 1 - 1
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,4}|museum|travel)'
 	);
 
 /**