From af69a68c39c78c4fe3c6ee388b7ee21f80068529 Mon Sep 17 00:00:00 2001 From: Jovial Joe Jayarson Date: Tue, 2 Apr 2024 15:47:09 +0530 Subject: [PATCH] patch: supported extended latin in username --- src/validators/email.py | 6 ++++-- src/validators/url.py | 6 ++++-- tests/test_email.py | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/validators/email.py b/src/validators/email.py index 5b57395c..eff09bd3 100644 --- a/src/validators/email.py +++ b/src/validators/email.py @@ -84,10 +84,12 @@ def email( ) ) if re.match( + # extended latin + r"(^[\u0100-\u017F\u0180-\u024F]" # dot-atom - r"(^[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$" + + r"|[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$" # quoted-string - + r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"$)', + + r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\011.])*"$)', username_part, re.IGNORECASE, ) diff --git a/src/validators/url.py b/src/validators/url.py index 3c86f0a6..779761be 100644 --- a/src/validators/url.py +++ b/src/validators/url.py @@ -13,10 +13,12 @@ @lru_cache def _username_regex(): return re.compile( + # extended latin + r"(^[\u0100-\u017F\u0180-\u024F]" # dot-atom - r"(^[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$" + + r"|[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$" # non-quoted-string - + r"|^([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*$)", + + r"|^([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\011.])*$)", re.IGNORECASE, ) diff --git a/tests/test_email.py b/tests/test_email.py index 733c5c5d..029c45e7 100644 --- a/tests/test_email.py +++ b/tests/test_email.py @@ -17,6 +17,8 @@ ("example@valid-with-hyphens.com",), ("test@domain.with.idn.tld.उदाहरण.परीक्षा",), ("email@localhost.in",), + ("Łókaść@email.com",), + ("łemłail@here.com",), ("email@localdomain.org",), ('"\\\011"@here.com',), ],