diff options
| author | Jannis Leidel <jannis@leidel.info> | 2011-02-12 19:24:17 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2011-02-12 19:24:17 +0000 |
| commit | 90ee3af279bb5b5c35d3fe22c5d6e07449ce65fc (patch) | |
| tree | d6392caed7eee3fe17c1b2c924a450ad23f4fd27 | |
| parent | 48fe6099c06cc84d666d4032d746c53be43ee196 (diff) | |
[1.2.X] Fixed #12988 -- Extended regular expression of the URLValidator 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
| -rw-r--r-- | django/core/validators.py | 2 | ||||
| -rw-r--r-- | tests/regressiontests/forms/tests/fields.py | 35 |
2 files changed, 28 insertions, 9 deletions
diff --git a/django/core/validators.py b/django/core/validators.py index b1b82dbf0d..dad0a7924f 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -41,7 +41,7 @@ class RegexValidator(object): class URLValidator(RegexValidator): regex = re.compile( r'^https?://' # http:// or https:// - r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?|' #domain... + r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain... r'localhost|' #localhost... r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip r'(?::\d+)?' # optional port diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py index e7516ad737..f198e6c796 100644 --- a/tests/regressiontests/forms/tests/fields.py +++ b/tests/regressiontests/forms/tests/fields.py @@ -567,13 +567,6 @@ class FieldsTests(TestCase): f.clean('http://google.com/we-love-microsoft.html') # good domain, bad page except ValidationError, e: self.assertEqual("[u'This URL appears to be a broken link.']", str(e)) - # Valid and existent IDN - self.assertEqual(u'http://\u05e2\u05d1\u05e8\u05d9\u05ea.idn.icann.org/', f.clean(u'http://עברית.idn.icann.org/')) - # Valid but non-existent IDN - try: - f.clean(u'http://broken.עברית.idn.icann.org/') - except ValidationError, e: - self.assertEqual("[u'This URL appears to be a broken link.']", str(e)) def test_urlfield_4(self): f = URLField(verify_exists=True, required=False) @@ -597,10 +590,36 @@ class FieldsTests(TestCase): self.assertEqual(u'http://example.com/', f.clean('http://example.com')) self.assertEqual(u'http://example.com/test', f.clean('http://example.com/test')) - def test_urlfield_ticket11826(self): + def test_urlfield_8(self): + # ticket #11826 f = URLField() self.assertEqual(u'http://example.com/?some_param=some_value', f.clean('http://example.com?some_param=some_value')) + def test_urlfield_9(self): + f = URLField(verify_exists=False) + urls = ( + u'http://עברית.idn.icann.org/', + u'http://sãopaulo.com/', + u'http://sãopaulo.com.br/', + u'http://пример.испытание/', + u'http://مثال.إختبار/', + u'http://例子.测试/', + u'http://例子.測試/', + u'http://उदाहरण.परीक्षा/', + u'http://例え.テスト/', + u'http://مثال.آزمایشی/', + u'http://실례.테스트/', + u'http://العربية.idn.icann.org/', + ) + for url in urls: + # Valid and existent IDN + self.assertEqual(url, f.clean(url)) + # Valid but non-existent IDN + try: + f.clean(u'http://broken.עברית.idn.icann.org/') + except ValidationError, e: + self.assertEqual("[u'This URL appears to be a broken link.']", str(e)) + # BooleanField ################################################################ def test_booleanfield_1(self): |
