Skip to content
Open
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
7 changes: 6 additions & 1 deletion src/validators/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def domain(
service_record = r"_" if rfc_2782 else ""
trailing_dot = r"\.?$" if rfc_1034 else r"$"

encoded = value.encode("idna").decode("utf-8")
if len(encoded.rstrip(".")) > 253:
# ref: RFC 1035, presentation form is limited to 253 characters
return False

return not re.search(r"\s|__+", value) and re.match(
# First character of the domain
rf"^(?:[a-z0-9{service_record}]"
Expand All @@ -94,7 +99,7 @@ def domain(
+ r"+[a-z0-9][a-z0-9-_]{0,61}"
# Last character of the gTLD
+ rf"[a-z]{trailing_dot}",
value.encode("idna").decode("utf-8"),
encoded,
re.IGNORECASE,
)
except UnicodeError as err:
Expand Down