ajv-validator / ajv-validator/ajv-formats
date-time accepts timestamps without `"T"` separator between date and time
- Lingua principale
- TypeScript
- Stelle
- 228
- Fork
- 42
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
According to the [JSON Schema Validation spec, section 7.3.1](https://tools.ietf.org/id/draft-handrews-json-schema-validation-01.html#rfc.section.7.3.1) and ajv-formats' documentation, the `date-time` format should validate a string against the `date-time` production of [RFC 3339, section 5.6](https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6).
This production requires the date and time components to be separated by `"T"` or `"t"`.
The validation regex used in ajv-formats 2.1.1 however also accepts strings like `"2023-01-22 11:11:11.123"` with a whitespace character separating the date and time components (note the `[t\s]` portion):
```js
/^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i
```
This issue will be addressed in version 3. I am posting this issue for troubleshooting/documentation.
A workaround for ajv-formats 2.1.1 is to add a `pattern()` to the schema, e.g. using a slight variation of [the regular expression used in ajv-formats 3](https://github.com/ajv-validator/ajv-formats/blob/4dd65447575b35d0187c6b125383366969e6267e/src/formats.ts#L105):
```js
S.string().format('date-time').pattern(/^\d\d\d\d-[0-1]\d-[0-3]\d[tT](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:[zZ]|[+-]\d\d(?::?\d\d)?)$/)
```
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.