Joi.string().isoDate() accepts iso strings that have invalid values, but have valid iso string formats
- Dominant language
- JavaScript
- Stars
- 21.2k
- Forks
- 1.5k
- Avg merge
- 4h 57m
- Merged PRs (30d)
- 14
Description
#### 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.
```ts
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](https://github.com/sideway/joi/blob/master/lib/types/string.js#L804) 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.
Contributor guide
Assessment
This issue has not been assessed yet.