Accept trailing dot on simple hostnames with rfc_1034#462
Open
assinscreedFC wants to merge 1 commit into
Open
Conversation
hostname('ie', rfc_1034=True) is valid, but hostname('ie.', rfc_1034=True)
was rejected. The RFC 1034 trailing dot was only handled by domain() (for
dotted names); a simple, single-label hostname went through
_simple_hostname_regex(), which does not allow a trailing dot, so it failed.
Strip an optional trailing dot before the simple-hostname check when
rfc_1034 is set, so a single-label hostname behaves consistently with and
without the dot. The dot is still rejected when rfc_1034 is False.
Refs python-validators#442
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refs #442.
rfc_1034is documented as "Allow trailing dot in domain/host name", but it only worked for dotted names (handled bydomain()):A simple, single-label hostname goes through
_simple_hostname_regex(), which does not permit a trailing dot, so"ie."failed even withrfc_1034=True, while"ie"passed.Fix
Strip an optional trailing dot before the simple-hostname check when
rfc_1034is set, so a single-label hostname behaves the same with and without the dot. The trailing dot is still rejected whenrfc_1034isFalse.Scope
This addresses the
hostname()inconsistency from #442. I deliberately leftdomain()'s rejection of bare single-label names (domain("ie")→ False with or without a dot) unchanged, since whether a single label counts as a "domain" is a separate policy question — happy to follow up if you'd like it changed too.Test plan
tests/test_hostname.py(valid withrfc_1034=True, invalid without).pytest tests/test_hostname.py tests/test_domain.py— 90 passed.ruff check/ruff format --check— clean.tests/crypto_addresses/test_eth_address.py(present on a clean checkout, before this change).