From e777c2a40c07d01b722d54d9a4d0b8ac59b50dc7 Mon Sep 17 00:00:00 2001 From: 0x2b3bfa0 <0x2b3bfa0+git@googlemail.com> Date: Fri, 5 Mar 2021 19:33:18 +0100 Subject: [PATCH] Update the user validation regex and message ...in order to allow user names beginning with a non-alphabetic character. --- invenio_userprofiles/validators.py | 6 +++--- tests/test_validators.py | 9 +++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/invenio_userprofiles/validators.py b/invenio_userprofiles/validators.py index d79dd29..afaf19e 100644 --- a/invenio_userprofiles/validators.py +++ b/invenio_userprofiles/validators.py @@ -14,12 +14,12 @@ from flask_babelex import lazy_gettext as _ -username_regex = re.compile('^[a-zA-Z][a-zA-Z0-9-_]{2}[a-zA-Z0-9-_]*$') +username_regex = re.compile('^[a-zA-Z0-9-_]{3,}$') """Username rules.""" USERNAME_RULES = _( - 'Username must start with a letter, be at least three characters long and' - ' only contain alphanumeric characters, dashes and underscores.') + 'Username must be at least three characters long and only contain' + ' alphanumeric characters, dashes and underscores.') """Description of username validation rules. .. note:: Used for both form help text and for form validation error.""" diff --git a/tests/test_validators.py b/tests/test_validators.py index 9f06827..fce8583 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -16,7 +16,7 @@ test_usernames = { 'valid': 'Good-Name_9', - 'invalid_begins_with_number': '9CantStartWithNumber', + 'valid_begins_with_number': '9CanStartWithNumber', 'invalid_characters': '_Containsi!!ega!Char acters*', 'invalid_short': 'ab', } @@ -24,12 +24,9 @@ def test_validate_username(app): """Test username validator.""" - # Goodname can contain letters, numbers and starts with a letter + # Goodname can contain letters and numbers validate_username(test_usernames['valid']) - - # Can't start with a number - with pytest.raises(ValueError): - validate_username(test_usernames['invalid_begins_with_number']) + validate_username(test_usernames['valid_begins_with_number']) # Can only contain latin letters and numbers with pytest.raises(ValueError):