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 · 2 comments
Closed

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

ljle opened this issue Sep 27, 2019 · 2 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@ljle
Copy link

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 Bug or defect label Oct 5, 2019
@hueniverse hueniverse added this to the 2.0.1 milestone Oct 5, 2019
@hueniverse
Copy link
Contributor

Bug is in joi: hapijs/joi#2168

hueniverse added a commit that referenced this issue Oct 5, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants