brandur / json_schema

A JSON Schema V4 and Hyperschema V4 parser and validator.
MIT License
230 stars 45 forks source link

Handle invalid date range in date format validation #122

Closed msgurgel-zz closed 3 years ago

msgurgel-zz commented 3 years ago

We are using format: date in a project and we realized that it allows for dates that exceed the valid range of a month or day. e.g. 2012-60-82 is considered a valid date in the current implementation.

This PR validates the date using the Date class to ensure the value is within the correct range.

We based this solution on an implemetation in a different JSON schema library: https://github.com/ruby-json-schema/json-schema/blob/765e6d8fdbfdaca1a42fa743f4621e757f9f6a03/lib/json-schema/attributes/formats/date.rb#L13

brandur commented 3 years ago

Thanks Mateus!

There is unfortunately a small chance that this could be a backwards incompatible change seen from a different perspective, even though it would only apply to schemas with invalid data. But I think the risk is small enough that I'm going to merge and release as a minor anyway.

brandur commented 3 years ago

Released as 0.21.0.