Skip to content

Commit 8607f5c

Browse files
authored
Merge pull request #3103 from ordinary9843/fix/describe-nan-allow
fix: allow NaN in schema describe() output validation
2 parents 384c5cd + d7994c8 commit 8607f5c

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/schemas.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ internals.desc.values = Joi.array()
212212
null,
213213
Joi.boolean(),
214214
Joi.function(),
215-
Joi.number().allow(Infinity, -Infinity),
215+
Joi.number().allow(Infinity, -Infinity, NaN),
216216
Joi.string().allow(''),
217217
Joi.symbol(),
218218
internals.desc.buffer,

test/manifest.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ describe('Manifest', () => {
254254
expect(Joi.invalid(1).allow(1).describe()).to.equal({ type: 'any', allow: [1] });
255255
});
256256

257+
it('handles NaN in allow list', () => {
258+
259+
const schema = Joi.number().allow(NaN);
260+
const desc = schema.describe();
261+
expect(desc.type).to.equal('number');
262+
expect(desc.allow).to.have.length(1);
263+
expect(Number.isNaN(desc.allow[0])).to.equal(true);
264+
});
265+
257266
it('describes ruleset changes', () => {
258267

259268
const schema = Joi.string().min(1).keep();

0 commit comments

Comments
 (0)