diff options
-rw-r--r-- | includes/common.inc | 23 | ||||
-rw-r--r-- | modules/simpletest/tests/common.test | 5 |
2 files changed, 18 insertions, 10 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); } } diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index c66007709..e6ebfa16c 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -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) { |