|
|
@@ -899,7 +899,7 @@ class Validation
|
|
|
* with an optional port number
|
|
|
* - an optional valid path
|
|
|
* - an optional query string (get parameters)
|
|
|
- * - an optional fragment (anchor tag)
|
|
|
+ * - an optional fragment (anchor tag) as defined in RFC 3986
|
|
|
*
|
|
|
* @param string $check Value to check
|
|
|
* @param bool $strict Require URL to be prefixed by a valid scheme (one of http(s)/ftp(s)/file/news/gopher)
|
|
|
@@ -908,12 +908,16 @@ class Validation
|
|
|
public static function url($check, $strict = false)
|
|
|
{
|
|
|
static::_populateIp();
|
|
|
- $validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~[]') . '\/0-9\p{L}\p{N}]|(%[0-9a-f]{2}))';
|
|
|
+ $alpha = '0-9\p{L}\p{N}';
|
|
|
+ $hex = '(%[0-9a-f]{2})';
|
|
|
+ $subDelimiters = preg_quote('/!"$&\'()*+,-.@_:;=~[]', '/');
|
|
|
+ $path = '([' . $subDelimiters . $alpha . ']|' . $hex . ')';
|
|
|
+ $fragmentAndQuery = '([\?' . $subDelimiters . $alpha . ']|' . $hex . ')';
|
|
|
$regex = '/^(?:(?:https?|ftps?|sftp|file|news|gopher):\/\/)' . (!empty($strict) ? '' : '?') .
|
|
|
'(?:' . static::$_pattern['IPv4'] . '|\[' . static::$_pattern['IPv6'] . '\]|' . static::$_pattern['hostname'] . ')(?::[1-9][0-9]{0,4})?' .
|
|
|
- '(?:\/?|\/' . $validChars . '*)?' .
|
|
|
- '(?:\?' . $validChars . '*)?' .
|
|
|
- '(?:#' . $validChars . '*)?$/iu';
|
|
|
+ '(?:\/' . $path . '*)?' .
|
|
|
+ '(?:\?' . $fragmentAndQuery . '*)?' .
|
|
|
+ '(?:#' . $fragmentAndQuery . '*)?$/iu';
|
|
|
|
|
|
return static::_check($check, $regex);
|
|
|
}
|