Skip to content

Inconsistent behavior with rfc_1034=True for domain validation #345

Closed

Description

@hwo411

Hello! I've recently faced a strange behavior that I'd like to report.

Tested on the latest version as of writing - 0.24.0

As per specs, rfc_1034=True allows trailing dot in the end of url, but it seems to require it in most of the cases:

>>> from validators import domain
>>> domain('example.com')
True
>>> domain('example.ru')
True
>>> domain('example.com.')
ValidationError(func=domain, args={'value': 'example.com.'})
>>> domain('example.ru.')
ValidationError(func=domain, args={'value': 'example.ru.'})
>>> domain('example.com', rfc_1034=True)
True
>>> domain('example.ru', rfc_1034=True)
ValidationError(func=domain, args={'value': 'example.ru', 'rfc_1034': True})
>>> domain('example.com.', rfc_1034=True)
True
>>> domain('example.ru.', rfc_1034=True)
True

As you can see, without rfc_1034 domains without trailing dot are valid and with trailing dot is invalid, which is correct.

However, with rfc_1034 it produces strange behavior:

.com is valid both with and without trailing dot (which is correct as per my understanding, because rfc_1034 allows trailing dot, but not requires it

.ru (and other domains like .fr) though is valid only with trailing dot, which is incorrect behavior in my opinion.

I checked the code and it seems that here https://github.com/python-validators/validators/blob/master/src/validators/domain.py#L50 the dot should be optional. But it does not explain why .com domain is not affected by this problem.

Am I missing something and this is expected or is there a bug and what should be the correct behavior? (My assumption is that dot is optional in rfc_1034)

Activity

  1. nandgator commented on Mar 27, 2024

    @nandgator
    Collaborator

    rfc_1034 allows trailing dot, but not requires it.

    True, but the current implementation

    rf"[A-Za-z]{r'.$' if rfc_1034 else r'$'}",

    requires a trailing dot, if rfc_1034=True

    .com is valid both with and without trailing dot.

    That is indeed strange. Thanks for brining this up!

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

    bugIssue: Works not as designed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions