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 undefinedhere. 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
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:And also:
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 isundefined
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