From 85959dcf9d757d7f2f4e7acae9438b9a40985112 Mon Sep 17 00:00:00 2001
From: Dheerendra Rathor <dheeru.rathor14@gmail.com>
Date: Wed, 28 Oct 2015 12:24:57 +0530
Subject: [PATCH] Fixed #25620 Changed '*' to '+' in domain name regex
Initially domain name regex had '*' which was allowing '.' to pass
the regex and making invalid URLs as valid (http://example...com).
Now atleast one unicode character will be required after '.' in
domain name regex
---
django/core/validators.py | 2 +-
tests/validators/invalid_urls.txt | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/django/core/validators.py b/django/core/validators.py
index ee026f5..69cc76f 100644
a
|
b
|
class URLValidator(RegexValidator):
|
84 | 84 | |
85 | 85 | # Host patterns |
86 | 86 | hostname_re = r'[a-z' + ul + r'0-9](?:[a-z' + ul + r'0-9-]*[a-z' + ul + r'0-9])?' |
87 | | domain_re = r'(?:\.(?!-)[a-z' + ul + r'0-9-]*(?<!-))*' |
| 87 | domain_re = r'(?:\.(?!-)[a-z' + ul + r'0-9-]+(?<!-))*' |
88 | 88 | tld_re = r'\.(?:[a-z' + ul + r']{2,}|xn--[a-z0-9]+)\.?' |
89 | 89 | host_re = '(' + hostname_re + domain_re + tld_re + '|localhost)' |
90 | 90 | |
diff --git a/tests/validators/invalid_urls.txt b/tests/validators/invalid_urls.txt
index a3393d7..12a1226 100644
a
|
b
|
http://.www.foo.bar./
|
49 | 49 | http://[::1:2::3]:8080/ |
50 | 50 | http://[] |
51 | 51 | http://[]:8080 |
| 52 | http://example..com/ |