Skip to content
Permalink
Browse files

Allow / and ? in fragments.

This matches the rules defined in RFC 3986 Section 3.5
  • Loading branch information...
markstory committed Sep 26, 2017
1 parent 2edf49c commit b6f439f4878e0a6f65cbf244ea87758906f3738c
Showing with 9 additions and 5 deletions.
  1. +9 −5 src/Validation/Validation.php
@@ -899,7 +899,7 @@ public static function range($check, $lower = null, $upper = null)
* 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 @@ public static function range($check, $lower = null, $upper = null)
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);
}

0 comments on commit b6f439f

Please sign in to comment.
You can’t perform that action at this time.