summaryrefslogtreecommitdiff
path: root/includes/common.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/common.inc')
-rw-r--r--includes/common.inc23
1 files changed, 14 insertions, 9 deletions
diff --git a/includes/common.inc b/includes/common.inc
index cdeeccc0e..5b6fb3726 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -1184,19 +1184,24 @@ function valid_email_address($mail) {
function valid_url($url, $absolute = FALSE) {
if ($absolute) {
return (bool)preg_match("
- /^ # Start at the beginning of the text
- (?:ftp|https?):\/\/ # Look for ftp, http, or https
- (?: # Userinfo (optional)
- (?:[\w\.\-\+%!$&'\(\)*\+,;=]+:)*
- [\w\.\-\+%!$&'\(\)*\+,;=]+@
+ /^ # Start at the beginning of the text
+ (?:ftp|https?):\/\/ # Look for ftp, http, or https schemes
+ (?: # Userinfo (optional) which is typically
+ (?:(?:[\w\.\-\+!$&'\(\)*\+,;=]|%[0-9a-f]{2})+:)* # a username or a username and password
+ (?:[\w\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})+@ # combination
)?
- (?:[a-z0-9\-\.%]+) # The domain
- (?::[0-9]+)? # Server port number (optional)
- (?:[\/|\?][\w#!:\.\?\+=&%@!$'~*,;\/\(\)\[\]\-]*)? # The path (optional)
+ (?:
+ (?:[a-z0-9\-\.]|%[0-9a-f]{2})+ # A domain name or a IPv4 address
+ |(?:\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\]) # or a well formed IPv6 address
+ )
+ (?::[0-9]+)? # Server port number (optional)
+ (?:[\/|\?]
+ (?:[\w#!:\.\?\+=&@!$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2}) # The path and query (optional)
+ *)?
$/xi", $url);
}
else {
- return (bool)preg_match("/^[\w#!:\.\?\+=&%@!$'~*,;\/\(\)\[\]\-]+$/i", $url);
+ return (bool)preg_match("/^(?:[\w#!:\.\?\+=&@!$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})+$/i", $url);
}
}