Content-Length: 290778 | pFad | http://github.com/python-validators/validators/pull/445/files

07 fix: reject hostnames exceeding 253 characters by Jo2234 · Pull Request #445 · python-validators/validators · GitHub
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
14 changes: 14 additions & 0 deletions src/validators/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ def hostname(
if not value:
return False

# Determine the host part (strip port if present) for length validation
host_part = value
if may_have_port:
if (seg := _port_validator(value)):
host_part = seg

# Strip IPv6 brackets for length check
host_part = host_part.lstrip("[").rstrip("]")

# RFC 1123: total hostname length must not exceed 253 characters
# (excluding optional trailing dot)
if len(host_part.rstrip(".")) > 253:
return False

if may_have_port and (host_seg := _port_validator(value)):
return (
(_simple_hostname_regex().match(host_seg) if maybe_simple else False)
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python-validators/validators/pull/445/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy