hapijs / joi

The most powerful data validation library for JS
Other
20.89k stars 1.51k forks source link

Domain validation not checking IANA registry by default #3007

Closed brunosilvano closed 8 months ago

brunosilvano commented 9 months ago

Runtime

both node.js and browser

Runtime version

node 18.16.1

Module version

17.11.0

Last module version without issue

No response

Used with

standalone

Any other relevant information

No response

What are you trying to achieve or the steps to reproduce?

When using Joi.string().domain() schema, I expected it to do TLD domain validation according to IANA registry by default, as this is implied by the docs:

tlds - options for TLD (top level domain) validation. By default, the TLD must be a valid name listed on the IANA registry. To disable validation, set tlds to false.

And also:

  • allow - one of:
    • true to use the IANA list of registered TLDs. This is the default value.

I think that it is either a bug when using the domain validation or an issue with the docs. The reason I think it could be a bug is because I tried to debug it a bit to see where it was failing and I saw that the options object is undefined here. Which might mean that Joi is not setting the expected default options.

It works as expected if you explicitly set the options, as in Joi.string().domain({ tlds: { allow: true } })

What was the result you got?

An invalid TLD passed validation when using Joi.string().domain() schema. Example: joi.dev.whatevertldiwant

What result did you expect?

I expected the validation to not pass, as the TLD does not exist in the IANA registry

fernandollisboa commented 8 months ago

I can work on that!