Skip to content

Commit

Permalink
Exclude domain names starting with -
Browse files Browse the repository at this point in the history
Related to 479aefc

Refs #3414
  • Loading branch information
markstory committed Apr 30, 2013
1 parent ac94d11 commit 2b0e10e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/Cake/Test/Case/Utility/ValidationTest.php
Expand Up @@ -1856,6 +1856,7 @@ public function testUrl() {
$this->assertFalse(Validation::url('http://_jabber._tcp.g_mail.com'));
$this->assertFalse(Validation::url('http://en.(wikipedia).org/'));
$this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode'));
$this->assertFalse(Validation::url('--.example.com'));
$this->assertFalse(Validation::url('www.cakephp.org', true));

$this->assertTrue(Validation::url('http://example.com/~userdir/subdir/index.html'));
Expand Down
9 changes: 4 additions & 5 deletions lib/Cake/Utility/Validation.php
@@ -1,7 +1,5 @@
<?php
/**
* Validation Class. Used for validation of model data
*
* PHP Version 5.x
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
Expand All @@ -13,24 +11,25 @@
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Utility
* @since CakePHP(tm) v 1.2.0.3830
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('Multibyte', 'I18n');
App::uses('File', 'Utility');
App::uses('CakeNumber', 'Utility');

// Load multibyte if the extension is missing.
if (!function_exists('mb_strlen')) {
class_exists('Multibyte');
}

/**
* Validation Class. Used for validation of model data
*
* Offers different validation methods.
*
* @package Cake.Utility
* @since CakePHP v 1.2.0.3830
*/
class Validation {

Expand All @@ -40,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' => '(?:[_a-z0-9][-_a-z0-9]*\.)*(?:[a-z0-9][-a-z0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,})'
);

/**
Expand Down

1 comment on commit 2b0e10e

@spiliot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now '--.example.com' is fixed but '_-' or '__.example.com' are still allowed. You need to make it [a-z] as numbers can't be in the first position of a (sub)domain either.

Please sign in to comment.