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
|
@deconstructible
|
||||||
class ASCIIUsernameValidator(validators.RegexValidator):
|
class ASCIIUsernameValidator(validators.RegexValidator):
|
||||||
regex = r'^[\w.@+-]+$'
|
regex = r'^[\w.@+-]+\Z'
|
||||||
message = _(
|
message = _(
|
||||||
'Enter a valid username. This value may contain only English letters, '
|
'Enter a valid username. This value may contain only English letters, '
|
||||||
'numbers, and @/./+/-/_ characters.'
|
'numbers, and @/./+/-/_ characters.'
|
||||||
|
@ -17,7 +17,7 @@ class ASCIIUsernameValidator(validators.RegexValidator):
|
||||||
|
|
||||||
@deconstructible
|
@deconstructible
|
||||||
class UnicodeUsernameValidator(validators.RegexValidator):
|
class UnicodeUsernameValidator(validators.RegexValidator):
|
||||||
regex = r'^[\w.@+-]+$'
|
regex = r'^[\w.@+-]+\Z'
|
||||||
message = _(
|
message = _(
|
||||||
'Enter a valid username. This value may contain only letters, '
|
'Enter a valid username. This value may contain only letters, '
|
||||||
'numbers, and @/./+/-/_ characters.'
|
'numbers, and @/./+/-/_ characters.'
|
||||||
|
|
|
@ -237,7 +237,7 @@ class UsernameValidatorsTests(SimpleTestCase):
|
||||||
invalid_usernames = [
|
invalid_usernames = [
|
||||||
"o'connell", "عبد ال",
|
"o'connell", "عبد ال",
|
||||||
"zerowidth\u200Bspace", "nonbreaking\u00A0space",
|
"zerowidth\u200Bspace", "nonbreaking\u00A0space",
|
||||||
"en\u2013dash",
|
"en\u2013dash", 'trailingnewline\u000A',
|
||||||
]
|
]
|
||||||
v = validators.UnicodeUsernameValidator()
|
v = validators.UnicodeUsernameValidator()
|
||||||
for valid in valid_usernames:
|
for valid in valid_usernames:
|
||||||
|
@ -250,7 +250,7 @@ class UsernameValidatorsTests(SimpleTestCase):
|
||||||
|
|
||||||
def test_ascii_validator(self):
|
def test_ascii_validator(self):
|
||||||
valid_usernames = ['glenn', 'GLEnN', 'jean-marc']
|
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()
|
v = validators.ASCIIUsernameValidator()
|
||||||
for valid in valid_usernames:
|
for valid in valid_usernames:
|
||||||
with self.subTest(valid=valid):
|
with self.subTest(valid=valid):
|
||||||
|
|
Loading…
Reference in New Issue