From c0e29cfb6a1f4754722ee4fb1acdeae11618c03b Mon Sep 17 00:00:00 2001 From: Jovial Joe Jayarson Date: Fri, 22 Mar 2024 16:36:21 +0530 Subject: [PATCH] fix: domain name not confirming to rfc_2782 --- src/validators/domain.py | 3 ++- tests/test_domain.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/validators/domain.py b/src/validators/domain.py index a8f991c4..c5eea7d4 100644 --- a/src/validators/domain.py +++ b/src/validators/domain.py @@ -42,7 +42,8 @@ def domain(value: str, /, *, rfc_1034: bool = False, rfc_2782: bool = False): # First character of the domain rf"^(?:[a-zA-Z0-9{'_'if rfc_2782 else ''}]" # Sub domain + hostname - + rf"(?:[a-zA-Z0-9-_]{{0,61}}[A-Za-z0-9{'_'if rfc_2782 else ''}])?\.)" + + rf"(?:[a-zA-Z0-9-{'_'if rfc_2782 else ''}]{{0,61}}" + + rf"[A-Za-z0-9{'_'if rfc_2782 else ''}])?\.)" # First 61 characters of the gTLD + r"+[A-Za-z0-9][A-Za-z0-9-_]{0,61}" # Last character of the gTLD diff --git a/tests/test_domain.py b/tests/test_domain.py index 4cd9c658..c8f5c4d9 100644 --- a/tests/test_domain.py +++ b/tests/test_domain.py @@ -11,8 +11,9 @@ ("value", "rfc_1034", "rfc_2782"), [ ("example.com", False, False), + ("exa_mple.com", False, True), ("xn----gtbspbbmkef.xn--p1ai", False, False), - ("underscore_subdomain.example.com", False, False), + ("underscore_subdomain.example.com", False, True), ("something.versicherung", False, False), ("someThing.versicherung.", True, False), ("11.com", False, False),