Skip to content

fix: domain name not confirming to rfc_2782 #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/validators/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down