Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #12988 -- Extended regular expression of the URLValidator to fu…

…lly support IDN-URLs, especially the long TLDs.

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

0 notes on commit 47b1a8e

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