Commit 388fe5b6 authored by Dries's avatar Dries

- Patch #124492 by mfer: added support for IPv6 and % characters. Comes with tests\!

parent 45fed79d
......@@ -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);
}
}
......
......@@ -557,6 +557,7 @@ class ValidUrlTestCase extends DrupalWebTestCase {
'john%20doe:secret:foo@example.org/',
'example.org/~,$\'*;',
'caf%C3%A9.example.org',
'[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html',
);
foreach ($url_schemes as $scheme) {
......@@ -576,6 +577,7 @@ class ValidUrlTestCase extends DrupalWebTestCase {
$invalid_ablosule_urls = array(
'',
'ex!ample.com',
'ex%ample.com',
);
foreach ($url_schemes as $scheme) {
......@@ -614,7 +616,8 @@ class ValidUrlTestCase extends DrupalWebTestCase {
function testInvalidRelative() {
$invalid_relative_urls = array(
'ex^mple',
'example<>'
'example<>',
'ex%ample',
);
foreach (array('', '/') as $front) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment