Skip to content

Joi.string().isoDate() accepts iso strings that have invalid values, but have valid iso string formats #2733

Open
@Toltar

Description

@Toltar

Context

  • node version: 14.18.3
  • module version with issue: 17.5.0
  • last module version without issue: N/A
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information:

What are you trying to achieve or the steps to reproduce?

I gave isoDate() an invalid date of 2022-02-30T07:45:10.179Z here, but errors is undefined.

import * as Joi from 'joi';

export const iso8601StringValidation = Joi.string().isoDate();

const isoString = '2022-02-30T07:45:10.179Z';
const result = iso8601StringValidation.validate(isoString); // errors are undefined and this is considered valid by joi

I know this seems kind of a niche bug, but I would think this would give an error at lease saying the user provided a ISO date that is simply just invalid. I notice in the code that we check if it is a valid date by checking if getTime() is NaN. But apparently, javascript just says that date is just March 1st of 2020.

What was the result you got?

The iso date is valid for JOI even though there is no 30th of February.

What result did you expect?

I expected joi to catch this and give an error message saying that this is not a valid date at all.

Metadata

Metadata

Assignees

Labels

supportQuestions, discussions, and general support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions