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

Issue with ".allow" whitelists #13

Closed
david-unergie opened this issue Nov 30, 2018 · 2 comments
Assignees
Labels
bug
Milestone

Comments

@david-unergie
Copy link

@david-unergie david-unergie commented Nov 30, 2018

Context

  • node version: v6.9.2
  • joi version: v10.6.0 / v11.4.0 / v12.0.0 / v13.7.0 / v14.3.0
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information: joi-date-extensions v1.2.0

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

The whitelisting behavior ".allow" seems not working since Joi.date().format() is in an external module.

Working with joi v9.2.0:

const joi = require('joi')
joi.date().format('YYYY-MM-DD').allow('epoch', 'start', 'end').validate('epoch')

Failing with v10.6.0 / v11.4.0 / v12.0.0 / v13.7.0 / v14.3.0:

const joi = require('joi').extend(require('joi-date-extensions'))
joi.date().format('YYYY-MM-DD').allow('epoch', 'start', 'end').validate('epoch')
// => "value" must be a string with one of the following formats [YYYY-MM-DD]

Which result you had ?

"value" must be a string with one of the following formats [YYYY-MM-DD]

What did you expect ?

No error

@david-unergie

This comment has been minimized.

Copy link
Author

@david-unergie david-unergie commented Nov 30, 2018

Usually, I use this kind of "alias" in conjuction of the ".raw()" behavior.

@david-unergie

This comment has been minimized.

Copy link
Author

@david-unergie david-unergie commented Dec 3, 2018

A surprising thing, .allow() works fine with null and '':

const joi = require('joi').extend(require('joi-date-extensions'))
joi.date().format('YYYY-MM-DD').allow('').validate('') // => works fine
joi.date().format('YYYY-MM-DD').allow(null).validate(null) // => works fine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.