Skip to content

Joi.string().domain() treats an email address as a valid domain name #2190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
PallasKatze opened this issue Oct 20, 2019 · 3 comments
Closed
Assignees
Labels
bug Bug or defect
Milestone

Comments

@PallasKatze
Copy link

Support plan

  • which support plan is this issue covered by? (e.g. Community, Core, Plus, or Enterprise): Community
  • is this issue currently blocking your project? (yes/no): yes
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: 10.15.3
  • module version with issue: 16.1.7
  • last module version without issue: -
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information: -

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

Joi.assert('mail@example.com', Joi.string().domain().required());

What was the result you got?

The line of code above does not throw any exception

What result did you expect?

I expect it to throw ValidationError because the input is an email address, not a domain name.

@PallasKatze PallasKatze added the support Questions, discussions, and general support label Oct 20, 2019
@yoavke
Copy link

yoavke commented Oct 20, 2019

I wouldn't expect domain to throw an error on an Email address, since it's also under the definition of a "Domain".
I'd use string().uri() (https://hapi.dev/family/joi/?v=16.1.7#stringurioptions) instead.

Every email address describes a domain, but it works only in this direction.

@PallasKatze
Copy link
Author

I wouldn't expect domain to throw an error on an Email address, since it's also under the definition of a "Domain".

A domain name is just a part of an email address. It also a part of URI but URI is not a valid input for .domain(). So I think that the name of this method is deceptive or the method is broken by itself.

I'd use string().uri() (https://hapi.dev/family/joi/?v=16.1.7#stringurioptions) instead.

This require the input string to be an URI, it fails on valid domain names.

@hueniverse hueniverse self-assigned this Nov 17, 2019
@hueniverse hueniverse added bug Bug or defect and removed support Questions, discussions, and general support labels Nov 17, 2019
@hueniverse hueniverse added this to the 16.1.8 milestone Nov 17, 2019
@hueniverse
Copy link
Contributor

Fixed via hapijs/address#19

@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

3 participants