hapijs / joi-date

Joi extensions for dates
Other
83 stars 25 forks source link

Fails to enforce required format when value is a number string #25

Closed ljle closed 4 years ago

ljle commented 4 years ago

Context

What are you trying to achieve or the steps to reproduce ? I'm trying to validate that a date string follows a format, but it throws no error when I use it with Joi.assert for numbers that are strings.

const Joi = require('@hapi/joi')
    .extend(require('@hapi/joi-date'));

const schema = Joi.date().format('YYYY-MM-DD');
Joi.assert('1', schema)
Joi.assert('10', schema)
Joi.assert('1000', schema)

https://runkit.com/ljle/joi-joi-date-potential-bug-with-number-strings

If I run it with something like 100x or 1-1, it does throw the error.

Which result you had ?

undefined

What did you expect ? A ValidationError thrown

exports.ValidationError: "value" must be in YYYY-MM-DD format
hueniverse commented 4 years ago

Bug is in joi: https://github.com/hapijs/joi/issues/2168

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.