Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #12988 -- Extended regular expression of the URLValidat…

…or to fully support IDN-URLs, especially the long TLDs.

Backport from trunk (r15502).

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15509 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 90ee3af279bb5b5c35d3fe22c5d6e07449ce65fc 1 parent 48fe609
Jannis Leidel authored February 12, 2011
2  django/core/validators.py
@@ -41,7 +41,7 @@ def __call__(self, value):
41 41
 class URLValidator(RegexValidator):
42 42
     regex = re.compile(
43 43
         r'^https?://' # http:// or https://
44  
-        r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?|' #domain...
  44
+        r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
45 45
         r'localhost|' #localhost...
46 46
         r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
47 47
         r'(?::\d+)?' # optional port
35  tests/regressiontests/forms/tests/fields.py
@@ -567,13 +567,6 @@ def test_urlfield_3(self):
567 567
             f.clean('http://google.com/we-love-microsoft.html') # good domain, bad page
568 568
         except ValidationError, e:
569 569
             self.assertEqual("[u'This URL appears to be a broken link.']", str(e))
570  
-        # Valid and existent IDN
571  
-        self.assertEqual(u'http://\u05e2\u05d1\u05e8\u05d9\u05ea.idn.icann.org/', f.clean(u'http://עברית.idn.icann.org/'))
572  
-        # Valid but non-existent IDN
573  
-        try:
574  
-            f.clean(u'http://broken.עברית.idn.icann.org/')
575  
-        except ValidationError, e:
576  
-            self.assertEqual("[u'This URL appears to be a broken link.']", str(e))
577 570
 
578 571
     def test_urlfield_4(self):
579 572
         f = URLField(verify_exists=True, required=False)
@@ -597,10 +590,36 @@ def test_urlfield_7(self):
597 590
         self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
598 591
         self.assertEqual(u'http://example.com/test', f.clean('http://example.com/test'))
599 592
 
600  
-    def test_urlfield_ticket11826(self):
  593
+    def test_urlfield_8(self):
  594
+        # ticket #11826
601 595
         f = URLField()
602 596
         self.assertEqual(u'http://example.com/?some_param=some_value', f.clean('http://example.com?some_param=some_value'))
603 597
 
  598
+    def test_urlfield_9(self):
  599
+        f = URLField(verify_exists=False)
  600
+        urls = (
  601
+            u'http://עברית.idn.icann.org/',
  602
+            u'http://sãopaulo.com/',
  603
+            u'http://sãopaulo.com.br/',
  604
+            u'http://пример.испытание/',
  605
+            u'http://مثال.إختبار/',
  606
+            u'http://例子.测试/',
  607
+            u'http://例子.測試/',
  608
+            u'http://उदाहरण.परीक्षा/',
  609
+            u'http://例え.テスト/',
  610
+            u'http://مثال.آزمایشی/',
  611
+            u'http://실례.테스트/',
  612
+            u'http://العربية.idn.icann.org/',
  613
+        )
  614
+        for url in urls:
  615
+            # Valid and existent IDN
  616
+            self.assertEqual(url, f.clean(url))
  617
+        # Valid but non-existent IDN
  618
+        try:
  619
+            f.clean(u'http://broken.עברית.idn.icann.org/')
  620
+        except ValidationError, e:
  621
+            self.assertEqual("[u'This URL appears to be a broken link.']", str(e))
  622
+
604 623
     # BooleanField ################################################################
605 624
 
606 625
     def test_booleanfield_1(self):

0 notes on commit 90ee3af

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