Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.844
diff -u -p -r1.844 common.inc
--- includes/common.inc	10 Jan 2009 11:50:11 -0000	1.844
+++ includes/common.inc	10 Jan 2009 15:51:54 -0000
@@ -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
+      (?:                                                     # Userinfo (optional)
+        (?:(?:[\w\.\-\+!$&'\(\)*\+,;=]|%[0-9a-f]{2})+:)*
+        (?:[\w\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})+@
       )?
-      (?:[a-z0-9\-\.%]+)                                # The domain
-      (?::[0-9]+)?                                      # Server port number (optional)
-      (?:[\/|\?][\w#!:\.\?\+=&%@!$'~*,;\/\(\)\[\]\-]*)? # The path (optional)
+      (?:                                                     # The domain
+        (?:[a-z0-9\-\.]|%[0-9a-f]{2})+                        # Domain name or IPv4
+        |(?:\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\])         # or IPv6
+      )
+      (?::[0-9]+)?                                            # Server port number (optional)
+      (?:[\/|\?]
+        (?:[\w#!:\.\?\+=&@!$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})  # The path (optional)
+      *)?
     $/xi", $url);
   }
   else {
-    return (bool)preg_match("/^[\w#!:\.\?\+=&%@!$'~*,;\/\(\)\[\]\-]+$/i", $url);
+    return (bool)preg_match("/^(?:[\w#!:\.\?\+=&@!$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})+$/i", $url);
   }
 }
 
Index: modules/simpletest/tests/common.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v
retrieving revision 1.20
diff -u -p -r1.20 common.test
--- modules/simpletest/tests/common.test	8 Jan 2009 19:09:49 -0000	1.20
+++ modules/simpletest/tests/common.test	10 Jan 2009 15:51:54 -0000
@@ -557,6 +557,7 @@ class ValidUrlTestCase extends DrupalWeb
       '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 DrupalWeb
     $invalid_ablosule_urls = array(
       '',
       'ex!ample.com',
+      'ex%ample.com',
     );
 
     foreach ($url_schemes as $scheme) {
@@ -614,7 +616,8 @@ class ValidUrlTestCase extends DrupalWeb
   function testInvalidRelative() {
     $invalid_relative_urls = array(
       'ex^mple',
-      'example<>'
+      'example<>',
+      'ex%ample',
     );
 
     foreach (array('', '/') as $front) {
