Skip to content

Commit

Permalink
Updated Validate::url, allow hostnames with no domain, allow paths in…
Browse files Browse the repository at this point in the history
… URLs, second fix to #2847
  • Loading branch information
Woody Gilk committed Jun 23, 2010
1 parent 1d2e3c3 commit 8e3a625
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion classes/kohana/validate.php
Expand Up @@ -145,7 +145,17 @@ public static function email_domain($email)
public static function url($url)
{
// Regex taken from http://fightingforalostcause.net/misc/2006/compare-email-regex.php
return (bool) preg_match('/^[a-z0-9+-.]+:\/\/(((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?$/i', $url);
// Added the scheme and path parts to test URLs

$scheme = '[a-z0-9+-.]+';
$host = '(([a-z0-9]{1}[a-z0-9-]+[a-z0-9]{1}|[a-z])\.?)+([a-z]{2,6})?';
$ipaddr = '(\d{1,3}.){3}\d{1,3}';
$port = '(\:\d{1,5})?';
$path = '(/.+)?';

$regex = "!^{$scheme}://({$host}|{$ipaddr}){$port}{$path}$!i";

return (bool) preg_match($regex, $url);
}

/**
Expand Down

0 comments on commit 8e3a625

Please sign in to comment.