mirror of https://github.com/django/django.git
Fixed #30257 -- Made UsernameValidators prohibit trailing newlines.
This commit is contained in:
parent
ea071870f9
commit
cbf7e71558
|
@ -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.'
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue