Skip to content

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

Closed as not planned

Description

@niallor

Syntactically valid, top-level domain names, with and without the final (RFC1034) dot,
are rejected by validators.domain().

Syntactically valid, top-level domain names, but only with the final (RFC1034) dot,
are rejected by validators.hostname().

In each case, this is incorrect.

Details are shown in the test run recorded below.

$ python
Python 3.13.1 (heads/ech:01878d639d, Dec  7 2025, 16:31:00) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> from validators import __version__ as version
>>> from validators import domain as is_domain
>>> from validators import hostname as is_hostname
>>> from pprint import pprint
>>> 
>>> version
'0.35.0'
>>> 
>>> samples = [ 'yu.', 'yu', 'yugoslavia.yu.', 'yugoslavia.yu', 'ie.', 'ie', 'defo.ie.', 'defo.ie' ]
>>> 
>>> pprint(list(map(lambda x: (x, is_domain(x, rfc_1034=True)), samples)))
[('yu.', ValidationError(func=domain, args={'value': 'yu.', 'rfc_1034': True})),
 ('yu', ValidationError(func=domain, args={'value': 'yu', 'rfc_1034': True})),
 ('yugoslavia.yu.', True),
 ('yugoslavia.yu', True),
 ('ie.', ValidationError(func=domain, args={'value': 'ie.', 'rfc_1034': True})),
 ('ie', ValidationError(func=domain, args={'value': 'ie', 'rfc_1034': True})),
 ('defo.ie.', True),
 ('defo.ie', True)]
>>> 
>>> pprint(list(map(lambda x: (x, is_hostname(x, rfc_1034=True, maybe_simple=True)), samples)))
[('yu.',
  ValidationError(func=hostname, args={'value': 'yu.', 'rfc_1034': True, 'maybe_simple': True})),
 ('yu', True),
 ('yugoslavia.yu.', True),
 ('yugoslavia.yu', True),
 ('ie.',
  ValidationError(func=hostname, args={'value': 'ie.', 'rfc_1034': True, 'maybe_simple': True})),
 ('ie', True),
 ('defo.ie.', True),
 ('defo.ie', True)]
>>> 

Activity

  1. nandgator commented on Oct 10, 2026

    @nandgator
    Collaborator

    Partly fixed: hostname('yu.', rfc_1034=True) (a single label with the RFC 1034 trailing dot) is now accepted (#462). What remains is domain('yu') / domain('ie.'): domain() requires a dotted name with a TLD by design, whereas a bare single label is covered by hostname(..., maybe_simple=True). Leaving this open for a maintainer decision on whether domain() should accept single labels.

  2. nandgator commented on Oct 10, 2026

    @nandgator
    Collaborator

    Decision: domain() keeps requiring a dotted name with a TLD, so domain('yu') and domain('ie.') stay invalid by design. The hostname half of this report is fixed (#462): hostname('yu.', rfc_1034=True) is accepted, and single-label names are validated with hostname(..., maybe_simple=True). Thanks for the detailed report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions