From 8c417564c7317a46883a779b765e54a28dbc7164 Mon Sep 17 00:00:00 2001 From: Alexey Sveshnikov Date: Fri, 3 Jul 2015 19:35:55 +0300 Subject: [PATCH] [1.8.x] Fixed #25059 -- Allowed Punycode TLDs in URLValidator Backport of bc98bc56a52860688ea0ae2ec7b9e59ddb72a811 from master --- django/core/validators.py | 2 +- docs/releases/1.8.3.txt | 3 +++ docs/spelling_wordlist | 1 + tests/validators/invalid_urls.txt | 1 + tests/validators/valid_urls.txt | 1 + 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/django/core/validators.py b/django/core/validators.py index bb8224f728..ac10d92956 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -74,7 +74,7 @@ class URLValidator(RegexValidator): # Host patterns hostname_re = r'[a-z' + ul + r'0-9](?:[a-z' + ul + r'0-9-]*[a-z' + ul + r'0-9])?' domain_re = r'(?:\.[a-z' + ul + r'0-9]+(?:[a-z' + ul + r'0-9-]*[a-z' + ul + r'0-9]+)*)*' - tld_re = r'\.[a-z' + ul + r']{2,}\.?' + tld_re = r'\.(?:[a-z' + ul + r']{2,}|xn--[a-z0-9]+)\.?' host_re = '(' + hostname_re + domain_re + tld_re + '|localhost)' regex = re.compile( diff --git a/docs/releases/1.8.3.txt b/docs/releases/1.8.3.txt index 600291d902..104d6eb725 100644 --- a/docs/releases/1.8.3.txt +++ b/docs/releases/1.8.3.txt @@ -92,3 +92,6 @@ Bugfixes * Fixed a regression in the ``unordered_list`` template filter on certain inputs (:ticket:`25031`). + +* Fixed a regression in ``URLValidator`` that invalidated Punycode TLDs + (:ticket:`25059`). diff --git a/docs/spelling_wordlist b/docs/spelling_wordlist index 60c9726791..f8fb27a9d7 100644 --- a/docs/spelling_wordlist +++ b/docs/spelling_wordlist @@ -492,6 +492,7 @@ proxied proxying pseudocode psycopg +Punycode Puthraya py pyformat diff --git a/tests/validators/invalid_urls.txt b/tests/validators/invalid_urls.txt index e225f256ba..9a4df36a20 100644 --- a/tests/validators/invalid_urls.txt +++ b/tests/validators/invalid_urls.txt @@ -6,6 +6,7 @@ http://.com http://invalid-.com http://-invalid.com http://invalid.com- +http://invalid.c-m http://inv-.alid-.com http://inv-.-alid.com file://localhost/path diff --git a/tests/validators/valid_urls.txt b/tests/validators/valid_urls.txt index 0d1dd779ea..040298f4fe 100644 --- a/tests/validators/valid_urls.txt +++ b/tests/validators/valid_urls.txt @@ -48,6 +48,7 @@ http://مثال.إختبار http://例子.测试 http://उदाहरण.परीक्षा http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com +http://xn--7sbb4ac0ad0be6cf.xn--p1ai http://1337.net http://a.b-c.de http://223.255.255.254