FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: rfc cases in the `domain` validator by nandgator · Pull Request #367 · python-validators/validators · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 9 additions & 5 deletions src/validators/domain.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,21 @@ def domain(
return False

try:
return not re.search(r"\s", value) and re.match(

service_record = r"_" if rfc_2782 else ""
trailing_dot = r"\.?$" if rfc_1034 else r"$"

return not re.search(r"\s|__+", value) and re.match(
Comment thread
nandgator marked this conversation as resolved.
# First character of the domain
rf"^(?:[a-z0-9{r'_?'if rfc_2782 else ''}]"
rf"^(?:[a-z0-9{service_record}]"
# Sub-domain
+ rf"(?:[a-z0-9-{r'_?'if rfc_2782 else ''}]{{0,61}}"
+ rf"(?:[a-z0-9-{service_record}]{{0,61}}"
# Hostname
+ rf"[a-z0-9{r'_?'if rfc_2782 else ''}])?\.)"
+ rf"[a-z0-9{service_record}])?\.)"
# First 61 characters of the gTLD
+ r"+[a-z0-9][a-z0-9-_]{0,61}"
# Last character of the gTLD
+ rf"[a-z]{r'.?$' if rfc_1034 else r'$'}",
+ rf"[a-z]{trailing_dot}",
value.encode("idna").decode("utf-8"),
re.IGNORECASE,
)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_domain.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
("3.cn.", True, False),
("_example.com", False, True),
("example_.com", False, True),
("_exa_mple_.com", False, True),
("a.cn", False, False),
("sub1.sub2.sample.co.uk", False, False),
("somerandomexample.xn--fiqs8s", False, False),
Expand Down Expand Up @@ -67,6 +68,9 @@ def test_returns_true_on_valid_top_level_domain(
("_example._com", False, False),
("example_.com", False, False),
("example", False, False),
("example.com!", True, False),
("example?.com", True, False),
("__exa__mple__.com", False, True),
("a......b.com", False, False),
("a.123", False, False),
("123.123", False, False),
Expand Down

Back | FazBrowse Home | New Git URL