1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #30257 -- Made UsernameValidators prohibit trailing newlines.

This commit is contained in:
Ryan J Schave 2019-03-22 13:16:26 -04:00 committed by Tim Graham
parent ea071870f9
commit cbf7e71558
2 changed files with 4 additions and 4 deletions

View File

@ -7,7 +7,7 @@ from django.utils.translation import gettext_lazy as _
@deconstructible
class ASCIIUsernameValidator(validators.RegexValidator):
regex = r'^[\w.@+-]+$'
regex = r'^[\w.@+-]+\Z'
message = _(
'Enter a valid username. This value may contain only English letters, '
'numbers, and @/./+/-/_ characters.'
@ -17,7 +17,7 @@ class ASCIIUsernameValidator(validators.RegexValidator):
@deconstructible
class UnicodeUsernameValidator(validators.RegexValidator):
regex = r'^[\w.@+-]+$'
regex = r'^[\w.@+-]+\Z'
message = _(
'Enter a valid username. This value may contain only letters, '
'numbers, and @/./+/-/_ characters.'

View File

@ -237,7 +237,7 @@ class UsernameValidatorsTests(SimpleTestCase):
invalid_usernames = [
"o'connell", "عبد ال",
"zerowidth\u200Bspace", "nonbreaking\u00A0space",
"en\u2013dash",
"en\u2013dash", 'trailingnewline\u000A',
]
v = validators.UnicodeUsernameValidator()
for valid in valid_usernames:
@ -250,7 +250,7 @@ class UsernameValidatorsTests(SimpleTestCase):
def test_ascii_validator(self):
valid_usernames = ['glenn', 'GLEnN', 'jean-marc']
invalid_usernames = ["o'connell", 'Éric', 'jean marc', "أحمد"]
invalid_usernames = ["o'connell", 'Éric', 'jean marc', "أحمد", 'trailingnewline\n']
v = validators.ASCIIUsernameValidator()
for valid in valid_usernames:
with self.subTest(valid=valid):