Addresses the feedback about regex.match

This commit is contained in:
Carlos Nihelton 2023-02-10 15:57:33 -03:00
parent 6be551d728
commit 4ff20dd135
No known key found for this signature in database
GPG Key ID: 6FE346D245197E9A
1 changed files with 5 additions and 3 deletions

View File

@ -78,15 +78,17 @@ class AdValidators:
# Ubiquity checks the admin name in two steps:
# 1. validate the first char against '[a-zA-Z]'
# 2. check the entire string against r'^[-a-zA-Z0-9_]+$'
if not re.match('[a-zA-Z]', name[0]):
# 2. check the entire string against r'[-a-zA-Z0-9_]+$'
# Because re.match always "interprets" the regex as if contains "^"
# we don't need to specify name[0]
if not re.match('[a-zA-Z]', name):
result.add(AdAdminNameValidation.INVALID_FIRST_CHAR)
if len(name) == 1:
return result
regex = re.compile(ADMIN_RE)
if not regex.match(name[1:]):
if not regex.search(name[1:]):
log.debug('<%s>: domain admin name contains invalid characters',
name)
result.add(AdAdminNameValidation.INVALID_CHARS)