Skip to content

Commit

Permalink
Merge pull request #1638 from paxa1887/#1637.Using_Number.MAX_SAFE_IN…
Browse files Browse the repository at this point in the history
…TEGER_throw_error

fix condition, add tests for safe numbers
  • Loading branch information
Marsup committed Nov 11, 2018
2 parents 12a4666 + a72af2f commit cebb4f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/types/number/index.js
Expand Up @@ -90,7 +90,7 @@ internals.Number = class extends Any {

if (isNumber) {
if (!this._flags.unsafe &&
(value >= Number.MAX_SAFE_INTEGER || value <= Number.MIN_SAFE_INTEGER)) {
(value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER)) {
result.errors = this.createError('number.unsafe', { value }, state, options);
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/types/number.js
Expand Up @@ -1414,6 +1414,18 @@ describe('number', () => {
});
});

describe('safe', () => {

it('should accept safe numbers', () => {

const t = Joi.number();
Helper.validate(t, [
[Number.MAX_SAFE_INTEGER, true, null, Number.MAX_SAFE_INTEGER],
[Number.MIN_SAFE_INTEGER, true, null, Number.MIN_SAFE_INTEGER]
]);
});
});

describe('min()', () => {

it('throws when limit is not a number', () => {
Expand Down

0 comments on commit cebb4f3

Please sign in to comment.