Skip to content

Number validation on '0x1' reports no error with a value of 0. #1113

@fadec

Description

@fadec

Context

  • node version: 7.5
  • joi version: 6.10.1
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

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

I was just playing around with this lib and I found something weird. Number('0x1') and parseInt('0x1') equal 1 but Joi doesn't see it that way. Joi converts a string '0x...' hex number to zero.

> j = require('joi'); j.validate('0x1', j.number())
{ error: null, value: 0 }

// yet

> j = require('joi'); j.validate('1', j.number())
{ error: null, value: 1 }

Which result you had ?

value = 0

What did you expect ?

value = 1

Metadata

Metadata

Assignees

Labels

bugBug or defectfeatureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions