Skip to content

fix(domain): accept single-label TLDs erroneously rejected by domain() and hostname()#476

Open
eeshsaxena wants to merge 1 commit into
python-validators:masterfrom
eeshsaxena:fix/domain-single-label-tld-rejected
Open

fix(domain): accept single-label TLDs erroneously rejected by domain() and hostname()#476
eeshsaxena wants to merge 1 commit into
python-validators:masterfrom
eeshsaxena:fix/domain-single-label-tld-rejected

Conversation

@eeshsaxena

Copy link
Copy Markdown

Fixes #442.

domain() and hostname() with
fc_1034=True rejected valid single-label domain names (ie, com, yu, ie.) because the internal regex used a + quantifier on the label group — which forces at least one dot separator. So a bare TLD like ie never matched.

Multi-label names like defo.ie and yugoslavia.yu were fine; only the single-label case was broken.

RFC 1034 §2.3.1 explicitly permits single-label names. The fix adds a second match path after the existing multi-label path: a bare TLD must be 2-63 alpha characters (optionally followed by a trailing dot when
fc_1034=True). Pure-digit strings like 123 are still rejected, consistent with the multi-label path.

Before:
\\python
domain('ie') # ValidationError (wrong)
domain('ie.') # ValidationError (wrong)
domain('com') # ValidationError (wrong)
hostname('ie.', rfc_1034=True) # ValidationError (wrong)
\\

After:
\\python
domain('ie') # True
domain('ie.', rfc_1034=True) # True
domain('ie.') # ValidationError (correct — trailing dot only allowed with rfc_1034)
domain('com') # True
hostname('ie.', rfc_1034=True) # True
domain('123') # ValidationError (still rejected)
\\

Multi-label domains, IDN, and all existing behaviour unchanged.

domain() and hostname() with rfc_1034=True silently rejected valid
single-label domain names (ie, com, yu, ie.) because the regex used a
+ quantifier on the label group, requiring at least one dot.

RFC 1034 s2.3.1 permits single-label names. Add a second match path
for bare TLDs (2-63 alpha chars, optional trailing dot) after the
existing multi-label path so that both cases are handled.

Fixes python-validators#442
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Top-level domain names are rejected erroneously by both hostname() and domain()

1 participant