diff --git a/django/core/validators.py b/django/core/validators.py index e0fd995227..8d87cef412 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -66,14 +66,25 @@ class RegexValidator(object): @deconstructible class URLValidator(RegexValidator): + ul = '\u00a1-\uffff' # unicode letters range (must be a unicode string, not a raw string) + + # IP patterns + ipv4_re = r'(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}' + ipv6_re = r'\[[0-9a-f:\.]+\]' # (simple regex, validated later) + + # 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,}\.?' + host_re = '(' + hostname_re + domain_re + tld_re + '|localhost)' + regex = re.compile( r'^(?:[a-z0-9\.\-]*)://' # scheme is validated separately - r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}(?