jonasschmidt / ex_json_schema

An Elixir JSON Schema validator
MIT License
366 stars 98 forks source link

Use `Date`/`DateTime` to parse `date`/`date-time` types #64

Closed amalbuquerque closed 3 years ago

amalbuquerque commented 3 years ago

Hi there, thank you for this library :raised_hands:

This is a small PR to use the native Date and DateTime modules (available since Elixir 1.6) to validate the date and date-time field types.

I've detected this problem since it was allowing a 2020-15-15 date, since the date was being validated against a \d{4}-\d{2}-\d{2} regex.

I've ran the draft-07 test suite, everything working as expected:

❯ MIX_ENV=test mix test test/json_schema_draft7_test_suite_test.exs:6
Excluding tags: [:test]
Including tags: [line: "6"]

**************........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Finished in 4.3 seconds (4.3s async, 0.00s sync)
806 tests, 0 failures, 14 skipped

Randomized with seed 33195
coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.03%) to 94.817% when pulling 3bed7ff5128f27ff2f04940f3202259d239889e8 on amalbuquerque:fix/parse-date-datetime-with-respective-elixir-modules into 56fb1e4708d48bda1414fa3d8d9dee8b7edc302f on jonasschmidt:master.

coveralls commented 3 years ago

Coverage Status

Coverage decreased (-0.1%) to 94.688% when pulling 3bed7ff5128f27ff2f04940f3202259d239889e8 on amalbuquerque:fix/parse-date-datetime-with-respective-elixir-modules into 56fb1e4708d48bda1414fa3d8d9dee8b7edc302f on jonasschmidt:master.

amalbuquerque commented 3 years ago

ℹ️ Also, this kind-of supersedes the other open PR: https://github.com/jonasschmidt/ex_json_schema/pull/58 (which by now has some conflicts).

jonasschmidt commented 3 years ago

Yes, nice. Now that support for Elixir < 1.6 is dropped anyway, this is a great idea. Did you run the rest of the tests as well? I'm not sure why the Travis integration doesn't work on PRs. I think it used to 🤔

amalbuquerque commented 3 years ago

Yes, nice. Now that support for Elixir < 1.6 is dropped anyway, this is a great idea. Did you run the rest of the tests as well? I'm not sure why the Travis integration doesn't work on PRs. I think it used to :thinking:

Will run the other test suites and report back.

jonasschmidt commented 3 years ago

mix test should run everything.

amalbuquerque commented 3 years ago

@jonasschmidt Everything's green as well:

❯ mix test
.......................................................................**************.....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................**************........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................**************..........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Finished in 5.1 seconds (5.1s async, 0.00s sync)
2104 tests, 0 failures, 42 skipped

Randomized with seed 336013
jonasschmidt commented 3 years ago

Perfect, I will merge and release a new version later today. Thank you for the contribution 🙌