jhthorsen / json-validator

:cop: Validate data against a JSON schema
https://metacpan.org/release/JSON-Validator
56 stars 57 forks source link

Make date-time regexp RFC3339 compatible #236

Closed Skeeve closed 3 years ago

Skeeve commented 3 years ago

RFC3339 states that the UTC offset needs to have 2 digit hour and minute offset.

Previous regexp allows for 1+ digits so "+1:1" and "-0123456789:9876543210" would be accepted.

Summary

While using Openapi Plugin I noticed that it doesn't accept ISO timestamps. While this is fine, as Openapi spec states that the format be RFC3339, I noticed that the regexp checking the dates is too lax.

Motivation

I see no advantage in accepting wrong time offsets like 123:567.

References

Discussion on IRC. Don't know how to link to it?

Skeeve commented 3 years ago

Tests submitted.

Link to spec: OpenAPI, RFC3339 See:

   time-hour       = 2DIGIT  ; 00-23
   time-minute     = 2DIGIT  ; 00-59
   time-numoffset  = ("+" / "-") time-hour ":" time-minute
Skeeve commented 3 years ago

I noticed a wrong test. You had a test against. '2017-03-29\t23:02:55-12:00' while you realy meant "2017-03-29\t23:02:55-12:00" as you didn want to check the non-acceptance of a \ followed by t but the non-acceptance of a tab. Fixed that.

I also added a check that the time offset is in the range of 00:00 to 23:59.

Skeeve commented 3 years ago

Since I messed it up, see a clean version here https://github.com/mojolicious/json-validator/pull/238