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
Summary
Refs #442.
rfc_1034 is documented as "Allow trailing dot in domain/host name", but it only worked for dotted names (handled by domain()):
A simple, single-label hostname goes through _simple_hostname_regex(), which does not permit a trailing dot, so "ie." failed even with rfc_1034=True, while "ie" passed.
Fix
Strip an optional trailing dot before the simple-hostname check when rfc_1034 is set, so a single-label hostname behaves the same with and without the dot. The trailing dot is still rejected when rfc_1034 is False.
Scope
This addresses the hostname() inconsistency from #442. I deliberately left domain()'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