Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #283 from mjtamlyn/ipv6-address-validation

Fixed #18779 -- URLValidator can't validate url with ipv6.
  • Loading branch information...
commit e41c30801433b30a1805ae8dd2fe79887c6dab0b 2 parents 16ab519 + bfa9fc6
Andrew Godwin authored August 18, 2012
3  django/core/validators.py
@@ -44,7 +44,8 @@ class URLValidator(RegexValidator):
44 44
         r'^(?:http|ftp)s?://' # http:// or https://
45 45
         r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
46 46
         r'localhost|' #localhost...
47  
-        r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
  47
+        r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|' # ...or ipv4
  48
+        r'\[?[A-F0-9]*:[A-F0-9:]+\]?)' # ...or ipv6
48 49
         r'(?::\d+)?' # optional port
49 50
         r'(?:/?|[/?]\S+)$', re.IGNORECASE)
50 51
 
12  tests/regressiontests/forms/tests/fields.py
@@ -668,6 +668,18 @@ def test_urlfield_9(self):
668 668
             # Valid IDN
669 669
             self.assertEqual(url, f.clean(url))
670 670
 
  671
+    def test_urlfield_10(self):
  672
+        """Test URLField correctly validates IPv6 (#18779)."""
  673
+        f = URLField()
  674
+        urls = (
  675
+            'http://::/',
  676
+            'http://6:21b4:92/',
  677
+            'http://[12:34:3a53]/',
  678
+            'http://[a34:9238::]:8080/',
  679
+        )
  680
+        for url in urls:
  681
+            self.assertEqual(url, f.clean(url))
  682
+
671 683
     def test_urlfield_not_string(self):
672 684
         f = URLField(required=False)
673 685
         self.assertRaisesMessage(ValidationError, "'Enter a valid URL.'", f.clean, 23)

0 notes on commit e41c308

Please sign in to comment.
Something went wrong with that request. Please try again.