Fix attempt for #695.

This commit is contained in:
Antoine Nguyen
2015-02-19 13:21:32 +01:00
parent 2e99cf7690
commit c4e693afeb
+10 -8
View File
@@ -333,17 +333,19 @@ class TabForms(object):
# #
def is_valid_host(host): def is_valid_hostname(hostname):
"""IDN compatible domain validator """Domain name validaton."""
""" if len(hostname) > 255:
host = host.encode('idna').lower() return False
if not hasattr(is_valid_host, '_re'): if hostname[-1] == ".":
is_valid_host._re = re.compile(r'^([0-9a-z][-\w]*[0-9a-z]\.)+[a-z0-9\-]{2,15}$') hostname = hostname[:-1] # strip exactly one dot from the
return bool(is_valid_host._re.match(host)) # right, if present
allowed = re.compile(r"(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE)
return all(allowed.match(x) for x in hostname.split("."))
def validate_domain_name(value): def validate_domain_name(value):
if not is_valid_host(value): if not is_valid_hostname(value):
raise ValidationError(_('Enter a valid domain name'), 'invalid') raise ValidationError(_('Enter a valid domain name'), 'invalid')