Skip to content

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

@niallor

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)]
>>> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions