From a5a3500630274302e4baf6c6ee85326c5d6f8010 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 20 Feb 2022 03:06:15 -0800 Subject: [PATCH] email: aliases: Minor refactoring to form validation Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/email/forms.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plinth/modules/email/forms.py b/plinth/modules/email/forms.py index f97721dd0..89fc89df9 100644 --- a/plinth/modules/email/forms.py +++ b/plinth/modules/email/forms.py @@ -38,13 +38,14 @@ class AliasCreateForm(forms.Form): def clean_alias(self): """Return the checked value for alias.""" value = self.data['alias'].strip().lower() - if not re.match('^[a-z0-9-_\\.]+$', value): + if not re.match(r'^[a-z0-9-_\.]+$', value): raise ValidationError(_('Contains illegal characters')) - if not re.match('^[a-z0-9].*[a-z0-9]$', value): + if not re.match(r'^[a-z0-9].*[a-z0-9]$', value): raise ValidationError(_('Must start and end with a-z or 0-9')) - if re.match('^[0-9]+$', value): + # For when uids are automatically aliased to username + if re.match(r'^[0-9]+$', value): raise ValidationError(_('Cannot be a number')) if aliases_module.exists(value):