tdegrunt / jsonschema

JSON Schema validation
Other
1.83k stars 263 forks source link

Mistake in RegExp format date-time #341

Closed epamroskoshinsky closed 2 years ago

epamroskoshinsky commented 3 years ago

"name": "jsonschema", "version": "1.4.0",

I have noticed, that the valid date-time format represented by the value "2021-03-18T18:00:00+0000" generate a validation error. Probably, this variant will be correct:

FORMAT_REGEXPS = {
  'date-time': /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])[tT ](2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])(\.\d+)?([zZ]|[+-]([0-5][0-9]):?(60|[0-5][0-9]))$/;

...

awwright commented 2 years ago

The value 2021-03-18T18:00:00+0000 is incorrect because the timezone offset is missing a :. In RFC 3339 and ISO 8601, this character is required:

date-time       = full-date "T" full-time
full-time       = partial-time time-offset
time-offset     = "Z" / time-numoffset
time-numoffset  = ("+" / "-") time-hour ":" time-minute

If you use 2021-03-18T18:00:00+00:00 (note added :) then this should be valid.