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

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

Closed
ljle opened this issue Sep 27, 2019 · 1 comment
Assignees
Labels
bug
Milestone

Comments

@ljle
Copy link

@ljle ljle commented Sep 27, 2019

Context

  • node version: v12.10.0
  • joi version: v16.1.4
  • environment (node, browser): node

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 hueniverse self-assigned this Sep 27, 2019
@hueniverse hueniverse changed the title Joi.assert with Joi.date() schema doesn't throw error on number strings Fails to enforce required format when value is a number string Oct 5, 2019
@hueniverse hueniverse added the bug label Oct 5, 2019
@hueniverse hueniverse added this to the 2.0.1 milestone Oct 5, 2019
@hueniverse

This comment has been minimized.

Copy link
Member

@hueniverse hueniverse commented Oct 5, 2019

Bug is in joi: hapijs/joi#2168

hueniverse added a commit that referenced this issue Oct 5, 2019
@hueniverse hueniverse closed this Oct 5, 2019
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.