mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-12-04 12:24:09 +01:00
Fix attempt for #695.
This commit is contained in:
@@ -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')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user