subdomain: Check for invalid characters before length.

I think it makes more sense to first tell the user that
the character you are entering is invalid than telling
minimum length requirement is not satisfied.

Fixes #3058.
This commit is contained in:
Vishnu Ks
2018-01-26 00:00:40 +05:30
committed by Tim Abbott
parent 6664c76a10
commit 1a1bc84d2c

View File

@@ -66,12 +66,12 @@ def check_subdomain_available(subdomain: str) -> None:
if is_root_domain_available():
return
raise ValidationError(error_strings['unavailable'])
if len(subdomain) < 3:
raise ValidationError(error_strings['too short'])
if subdomain[0] == '-' or subdomain[-1] == '-':
raise ValidationError(error_strings['extremal dash'])
if not re.match('^[a-z0-9-]*$', subdomain):
raise ValidationError(error_strings['bad character'])
if len(subdomain) < 3:
raise ValidationError(error_strings['too short'])
if is_reserved_subdomain(subdomain) or \
get_realm(subdomain) is not None:
raise ValidationError(error_strings['unavailable'])