Skip to content

Commit d7994c8

Browse files
committed
fix: allow NaN in schema describe() output validation
When a schema includes .allow(NaN), calling .describe() would throw a ValidationError because NaN was not listed as a valid item type in the internal manifest values schema. NaN is a valid JavaScript number and a legitimate value to allow in a joi schema. The fix adds NaN alongside the existing Infinity and -Infinity exceptions in the internals.desc.values definition. Fixes #3094
1 parent 481e270 commit d7994c8

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
@@ -210,7 +210,7 @@ internals.desc.values = Joi.array()
210210
null,
211211
Joi.boolean(),
212212
Joi.function(),
213-
Joi.number().allow(Infinity, -Infinity),
213+
Joi.number().allow(Infinity, -Infinity, NaN),
214214
Joi.string().allow(''),
215215
Joi.symbol(),
216216
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)