Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve DateTime validation #36

Open
amayer171 opened this issue May 9, 2018 · 2 comments
Open

Improve DateTime validation #36

amayer171 opened this issue May 9, 2018 · 2 comments

Comments

@amayer171
Copy link
Contributor

Date, Datetime, and Time validation is lacking. https://github.com/procore/brita/blob/master/lib/brita/type_validator.rb#L4

It currently matches a very generic range pattern that may lead to a database error when trying to parse an input value.

Here is an example:
datetime = DateTime.new(2016,12,24).to_s
=> "2016-12-24T00:00:00+00:00"

Constructing a query in postman with this value causes an error:
?filters[updated_at]=2016-12-24T00:00:00+00:00...2016-12-29T12:16:44+00:00

On the server this gets parsed into:
"filters"=>{"updated_at"=>"2016-12-24T00:00:00 00:00...2016-12-29T12:16:44 00:00"}

  • Note that + gets replaced with a blank space character.

This passes the range pattern but fails at the database leading to a 500 error.

@HParker
Copy link
Contributor

HParker commented May 9, 2018

Yes! we implicitly support ISO8601 only because that is all we test and what we document, but the thing that makes this hard is we use rails controller validations so we are limited by what that allows. If you can figure out how to enforce ISO8601 in a rails controller validation, we should totally do it.

@HParker
Copy link
Contributor

HParker commented May 9, 2018

A start is the C source that ruby uses here: https://ruby-doc.org/stdlib-2.1.1/libdoc/time/rdoc/Time.html#method-c-xmlschema

We might be able to steal the regex from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants