Skip to content

Commit

Permalink
Merge pull request python-validators#341 from yozachar/workshop
Browse files Browse the repository at this point in the history
fix: domain name not confirming to rfc_2782
  • Loading branch information
yozachar committed Mar 22, 2024
2 parents 7e799eb + c0e29cf commit 799e63b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
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

0 comments on commit 799e63b

Please sign in to comment.