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

"-0" throw number.unsafe #2091

Closed
zapolnoch opened this issue Aug 30, 2019 · 3 comments
Closed

"-0" throw number.unsafe #2091

zapolnoch opened this issue Aug 30, 2019 · 3 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@zapolnoch
Copy link

Context

  • node version: 12.6.0
  • joi version: 15.1.1
  • environment: node
  • used with: standalone

What are you trying to achieve or the steps to reproduce ?

const schema = Joi.number()
const result = schema.validate('-0')

Which result you had ?

error type 'number.unsafe'

What did you expect ?

{ error: null, value: 0 }

because:

const schema = Joi.number()
schema.validate('+0') // => { error: null, value: 0 }
@zapolnoch
Copy link
Author

I think the problem lies in this line.

parseFloat("-0").toString()		// "0"
internals.normalizeDecimal("-0")	// "-0"

@hueniverse hueniverse self-assigned this Aug 31, 2019
@hueniverse hueniverse added the bug Bug or defect label Aug 31, 2019
@hueniverse hueniverse added this to the 16.0.0 milestone Sep 3, 2019
@kanongil
Copy link
Contributor

kanongil commented Sep 3, 2019

@hueniverse I'm not a fan of converting the -0 value to 0. It means that the following produces different values:

schema.validate('-0'); // => { value: 0 }
schema.validate(-0); // => { value: -0 }

Also, Joi.number().integer().validate(-0) does not fail as expected.

@hueniverse
Copy link
Contributor

I think all -0 should be 0. It's just stupid. I'll make sure to make it consistent.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 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