Skip to content

64-bit limits in min()/max()/integer() #192

@emilv

Description

@emilv

We cannot use 64-bit integers (limit > 2^32) as limits for numbers, and they are not considered legal integers. This comes from the fact that bitwise operators in JS are defined to work on 32-bit values, and we use a bitwise OR to validate the limit in min, max and integer

Version

This have been in number.js since the beginning.

Reproduce:

var Joi = require('joi');

try { Joi.validate(1394035612552, Joi.number().min(1394035612500));
    } catch (e) { console.log(e); }
try { Joi.validate(1394035612552, Joi.number().max(1394035612600));
    } catch (e) { console.log(e); }
console.log(Joi.validate(1394035612552, Joi.number().integer()));

Result:

[Error: limit must be an integer]
[Error: limit must be an integer]
{ details: 
   [ { message: 'the value of <root> must be an integer',
       path: '<root>',
       type: 'number.int' } ],
  _object: 1394035612552,
  message: 'the value of <root> must be an integer' }

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