From de614ef7b3a929bda94a0209d3218099c65f8b08 Mon Sep 17 00:00:00 2001 From: Chris Wisdo <5473291+cwisdo@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:30:46 -0500 Subject: [PATCH] Fix email regex issue 140 --- src/validators/email.py | 10 +++++++--- tests/test_email.py | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/validators/email.py b/src/validators/email.py index eff09bd3..bc17d772 100644 --- a/src/validators/email.py +++ b/src/validators/email.py @@ -85,11 +85,15 @@ def email( ) if re.match( # extended latin - r"(^[\u0100-\u017F\u0180-\u024F]" + r"(^[\u0100-\u017F\u0180-\u024F\u00A0-\u00FF]" # dot-atom - + r"|[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$" + + r"|[\u0100-\u017F\u0180-\u024F\u00A0-\u00FF0-9a-z!#$%&'*+/=?^_`{}|~\-]+" + + r"(\.[\u0100-\u017F\u0180-\u024F\u00A0-\u00FF0-9a-z!#$%&'*+/=?^_`{}|~\-]+)*$" # quoted-string - + r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\011.])*"$)', + + r'|^"(' + + r"[\u0100-\u017F\u0180-\u024F\u00A0-\u00FF\001-\010\013\014\016-\037" + + r"!#-\[\]-\177]|\\[\011.]" + + r')*")$', username_part, re.IGNORECASE, ) diff --git a/tests/test_email.py b/tests/test_email.py index 029c45e7..56c95f37 100644 --- a/tests/test_email.py +++ b/tests/test_email.py @@ -48,6 +48,9 @@ def test_returns_true_on_valid_email(value: str): ('"test@test"@example.com',), # Quoted-string format (CR not allowed) ('"\\\012"@here.com',), + # Non-quoted space/semicolon not allowed + ("stephen smith@example.com",), + ("stephen;smith@example.com",), ], ) def test_returns_failed_validation_on_invalid_email(value: str):