python-validators/validators

Please distinguish between domain and FQDN

maaaaz opened this issue ยท 10 comments

maaaaz commented

Hello there,

Thanks for this project, it is really useful !

Could you add a "fqdn" validator (https://github.com/ypcrts/fqdn) to be able to distinguish between a domain and a FQDN ?
So far, we can't perform distinguished validations:

>>> validators.domain('foo.com')
True
>>> validators.domain('mail.foo.com')
True

Cheers!

I think that fqdn runs exactly the same validation that validators does. I just used fqdn with the domains in your example, and the results are identical:

>>> from fqdn import FQDN
>>> FQDN('foo.com').is_valid
True
>>> FQDN('mail.foo.com').is_valid
True

Hello there,

Thanks for this project, it is really useful !

Could you add a "fqdn" validator (https://github.com/ypcrts/fqdn) to be able to distinguish between a domain and a FQDN ? So far, we can't perform distinguished validations:

>>> validators.domain('foo.com')
True
>>> validators.domain('mail.foo.com')
True

Cheers!

@maaaaz, are you looking for RFC 1034 support? Please refer: https://python-validators.github.io/validators/reference/domain/


FQDN โŠ† DN. How do you propose to distinguish between workspace.google.com and www.google.com, since both of them are valid FQDN and hence valid DN?

maaaaz commented

@bencouture, thanks, interesting.

Maybe the following could work ?

  • Check if the entry follows this pattern : <second level domain name>.<top level domain>, with <top level domain> being an entry of the official TLD list.
    If yes, for instance "google.com", recognize it as a domain name.

  • If not, for instance "www.google.com", then recognize it as a FQDN.
    An even better version would be to specifically match this pattern <whatever>.<domain name>, with <domain name> being the above pattern.
    If yes, recognize it as an FQDN.

@maaaaz are you suggesting a parameter strictly_fqdn like this?

domain (
    value,
    /,
    *,
    strictly_fqdn = False,
    rfc_1034 = False,
    rfc_2782 = False
)
...

with such a behaviour?

>>> domain('github.com', strictly_fqdn=True)
False
>>> domain('www.github.com', strictly_fqdn=True)
True
>>> domain('gist.github.com', strictly_fqdn=False)
True
>>> domain('raw.github.com')
True
maaaaz commented

Yes, thanks this is perfect !

EDIT : why raw.github.com returns True without strictly_fqdn=True ?

Because False is the default value of the suggested strictly_fqdn parameter.


Wouldn't it be simpler to check if 'random.domain.name'.count('.') >= 2 given domain('random.domain.name') == True ?

maaaaz commented

Wouldn't it be simpler to check if 'random.domain.name'.count('.') >= 2 given domain('random.domain.name') == True ?

No, because some TLD already got 2 dots, for instance the co.uk ones: amazon.co.uk is a domain name.

Related: #67 & #198

This is the current implementation of TLD check

if consider_tld and value.rstrip(".").rsplit(".", 1)[-1].upper() not in _iana_tld():
return False

Can you suggest an algorithm for fqdn validation? (Something tells me it's recursive)