Skip to content

Commit 25fcef0

Browse files
authoredMar 28, 2025··
Fix email regex issue 140 (#411)
1 parent 9dac863 commit 25fcef0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed
 

‎src/validators/email.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,15 @@ def email(
8585
)
8686
if re.match(
8787
# extended latin
88-
r"(^[\u0100-\u017F\u0180-\u024F]"
88+
r"(^[\u0100-\u017F\u0180-\u024F\u00A0-\u00FF]"
8989
# dot-atom
90-
+ r"|[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$"
90+
+ r"|[\u0100-\u017F\u0180-\u024F\u00A0-\u00FF0-9a-z!#$%&'*+/=?^_`{}|~\-]+"
91+
+ r"(\.[\u0100-\u017F\u0180-\u024F\u00A0-\u00FF0-9a-z!#$%&'*+/=?^_`{}|~\-]+)*$"
9192
# quoted-string
92-
+ r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\011.])*"$)',
93+
+ r'|^"('
94+
+ r"[\u0100-\u017F\u0180-\u024F\u00A0-\u00FF\001-\010\013\014\016-\037"
95+
+ r"!#-\[\]-\177]|\\[\011.]"
96+
+ r')*")$',
9397
username_part,
9498
re.IGNORECASE,
9599
)

‎tests/test_email.py

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def test_returns_true_on_valid_email(value: str):
4848
('"test@test"@example.com',),
4949
# Quoted-string format (CR not allowed)
5050
('"\\\012"@here.com',),
51+
# Non-quoted space/semicolon not allowed
52+
("stephen smith@example.com",),
53+
("stephen;smith@example.com",),
5154
],
5255
)
5356
def test_returns_failed_validation_on_invalid_email(value: str):

0 commit comments

Comments
 (0)
Please sign in to comment.