summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-02-11 10:39:53 -0500
committerTim Graham <timograham@gmail.com>2016-02-18 19:51:29 -0500
commit07ffee641174b4c43986cd516fc39eec2d91a90e (patch)
tree077b6a480f767747140ce2e0186d2bf89856f97a /django
parent277b39cbbc5fe08740f74891cbf11ab9c3cf639b (diff)
[1.9.x] Fixed #26204 -- Reallowed dashes in top-level domains for URLValidator.
Thanks Shai Berger for the review. Backport of b1afebf882db5296cd9dcea26ee66d5250922e53 from master
Diffstat (limited to 'django')
-rw-r--r--django/core/validators.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/django/core/validators.py b/django/core/validators.py
index 69cc76ffab..852ff49358 100644
--- a/django/core/validators.py
+++ b/django/core/validators.py
@@ -85,7 +85,14 @@ 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-]+(?<!-))*'
- tld_re = r'\.(?:[a-z' + ul + r']{2,}|xn--[a-z0-9]+)\.?'
+ tld_re = (
+ '\.' # dot
+ '(?!-)' # can't start with a dash
+ '(?:[a-z' + ul + '-]{2,}' # domain label
+ '|xn--[a-z0-9]+)' # or punycode label
+ '(?<!-)' # can't end with a dash
+ '\.?' # may have a trailing dot
+ )
host_re = '(' + hostname_re + domain_re + tld_re + '|localhost)'
regex = _lazy_re_compile(