Skip to content

Domain validation not checking IANA registry by default #3007

@brunosilvano

Description

@brunosilvano

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

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions