Skip to content
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

Invalid input error validating link in schema #36

Closed
gpmarchi opened this issue Jul 13, 2021 · 1 comment
Closed

Invalid input error validating link in schema #36

gpmarchi opened this issue Jul 13, 2021 · 1 comment
Assignees
Labels
bug Bug or defect
Milestone

Comments

@gpmarchi
Copy link

Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): yes

Context

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

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

As discussed in the celebrate repo under issue #222, I'm getting an error when trying to validate a link inside my schema. I have detailed all the code I'm running under the celebrate issue, so if you guys need to see the code I suggest you link to that issue. This is the schema I'm referring to:

link: Joi.string()
   .uri({
      domain: {
         tlds: {
            allow: true,
         },
      },
   })
   .required()

And this is the content I'm trying to validate:

http:/instagram.com or http:instagram.com

So the issue I've been having with this is that whenever I try to pass on an invalid uri like the ones from the example above (missing a forward slash or both) I get an invalid input error.

What was the result you got?

This is the error message I got:

Error: Invalid input: domain must be a string
    at Object.exports.analyze (/Users/dev/Documents/Projetos/backend/node_modules/@sideway/address/lib/domain.js:21:15)
    at Object.exports.isValid (/Users/dev/Documents/Projetos/backend/node_modules/@sideway/address/lib/domain.js:101:21)
    at Object.validate (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/types/string.js:653:33)
    at Object.internals.rules (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/validator.js:394:33)
    at Object.exports.validate (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/validator.js:350:22)
    at internals.Base.$_validate (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/base.js:773:26)
    at Object.validate (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/types/keys.js:108:45)
    at Object.exports.validate (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/validator.js:325:26)
    at internals.Base.$_validate (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/base.js:773:26)
    at Object.validate (/Users/dev/Documents/Projetos/backend/node_modules/joi/lib/types/array.js:273:45)

What result did you expect?

I expect the library to identify my input as a wrong domain format and validate it accordingly giving me back a validation message instead of an error.

@hueniverse hueniverse transferred this issue from hapijs/joi Aug 1, 2021
@hueniverse hueniverse added the bug Bug or defect label Aug 1, 2021
@hueniverse hueniverse self-assigned this Aug 1, 2021
@hueniverse hueniverse added this to the 4.1.3 milestone Dec 1, 2021
@hueniverse
Copy link
Contributor

Fixed the throw on null (return missing domain error instead) and also prevented some edge cases about invalid http domains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants