From bc98bc56a52860688ea0ae2ec7b9e59ddb72a811 Mon Sep 17 00:00:00 2001
From: Alexey Sveshnikov <alexey.sveshnikov@gmail.com>
Date: Fri, 3 Jul 2015 19:35:55 +0300
Subject: [PATCH] Fixed #25059 -- Allowed Punycode TLDs in URLValidator

---
 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 3e4e744ff3..9feb33e8e9 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 ebc20f9b23..719fc3d31a 100644
--- a/docs/spelling_wordlist
+++ b/docs/spelling_wordlist
@@ -605,6 +605,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