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

NaN printed in cosole as null #696

Closed
rashtao opened this issue Jul 24, 2015 · 4 comments
Closed

NaN printed in cosole as null #696

rashtao opened this issue Jul 24, 2015 · 4 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@rashtao
Copy link

rashtao commented Jul 24, 2015

This code:

var schema = Joi.object().keys({
        date: Joi.date().allow(null)
});

Joi.assert({date: NaN}, schema);

prints in the console:

Error: {
  "date" [1]: null
}

[1] "date" must be a number of milliseconds or valid date string

and could be really confusing to debug!

@Marsup
Copy link
Collaborator

Marsup commented Jul 26, 2015

Unfortunately joi relies on JSON.stringify which transforms a few types, NaN being converted to null.
If you find a clever way to deal with it I'll take it.

@Marsup Marsup added the bug Bug or defect label Jul 29, 2015
@Marsup Marsup self-assigned this Jul 29, 2015
@mdibaiee
Copy link
Contributor

mdibaiee commented Oct 6, 2015

@Marsup I searched for this issue, the only "workaround" seems to be transforming NaN and Infinity to their string equivalents and then transforming them back while doing JSON.parse. Although I think we don't need the parse case here, as we're only printing it out.

If you think we would use this, I'd be happy to make a PR.

@Marsup
Copy link
Collaborator

Marsup commented Oct 7, 2015

Yup, I should port what I did in lab. If someone else is happy to do it then I'm fine with it :)

@Marsup
Copy link
Collaborator

Marsup commented Dec 18, 2015

Fixed by #735.

@Marsup Marsup closed this as completed Dec 18, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 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

3 participants