From 1a1bc84d2c35e2be806b60e10758efc378cd4d06 Mon Sep 17 00:00:00 2001 From: Vishnu Ks Date: Fri, 26 Jan 2018 00:00:40 +0530 Subject: [PATCH] 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. --- zerver/forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zerver/forms.py b/zerver/forms.py index 3ab8d1fcc1..a774cc24ff 100644 --- a/zerver/forms.py +++ b/zerver/forms.py @@ -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'])