Skip to content

fix: allow NaN in schema describe() output validation#3103

Merged
Marsup merged 1 commit intohapijs:masterfrom
ordinary9843:fix/describe-nan-allow
Mar 23, 2026
Merged

fix: allow NaN in schema describe() output validation#3103
Marsup merged 1 commit intohapijs:masterfrom
ordinary9843:fix/describe-nan-allow

Conversation

@ordinary9843
Copy link
Copy Markdown
Contributor

@ordinary9843 ordinary9843 commented Mar 22, 2026

Calling .describe() on a schema that includes .allow(NaN) throws a ValidationError.

const schema = Joi.number().allow(null, NaN);
schema.describe(); // throws

The issue is in internals.desc.values in lib/schemas.jsInfinity and -Infinity are listed as allowed number values, but NaN is not, so the describe output fails its own internal validation.

Adding NaN to the list fixes it. All existing tests still pass.

Fixes #3094

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 hapijs#3094
@Marsup Marsup added this to the 18.1.1 milestone Mar 23, 2026
@Marsup Marsup self-assigned this Mar 23, 2026
@Marsup Marsup added the bug Bug or defect label Mar 23, 2026
@Marsup
Copy link
Copy Markdown
Collaborator

Marsup commented Mar 23, 2026

Thanks!

@Marsup Marsup merged commit 8607f5c into hapijs:master Mar 23, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Bug or defect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

any.describe() throws an error if the schema contains .allow(NaN)

2 participants