Skip to content

Some exponential notation strings are validated as unsafe numbers #2672

@vvandens

Description

@vvandens

Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): yes

Context

  • node version: v12.22.6
  • module version with issue: 17.4.2
  • last module version without issue: N/A
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information:

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

const schema = Joi.number();
const validation = schema.validate('9.4e-1');
console.log(`value: ${validation.value}, message: ${validation.error}`);

What was the result you got?

value: 0.94, message: ValidationError: "value" must be a safe number

What result did you expect?

value: 0.94, message: undefined

I beleive that the problem lies in number.js#42 when the division hits a double precision value problem, i.e. :
0.94 / Math.pow(10, -1) results in 9.399999999999999

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions