hapijs / joi-date

Joi extensions for dates
Other
83 stars 25 forks source link

Issue with ".allow" whitelists #13

Closed david-unergie closed 4 years ago

david-unergie commented 5 years ago

Context

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 commented 5 years ago

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

david-unergie commented 5 years ago

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
lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.