whichdigital / active-rest-client

ActiveRestClient API Client
https://rubygems.org/gems/active_rest_client
MIT License
385 stars 44 forks source link

avoid error when parsing strings with iso dates in them #112

Closed yukideluxe closed 8 years ago

yukideluxe commented 8 years ago

Hello!

I found an issue when parsing a JSON response when some field includes a string with a iso8601 date in it (f.e "hello this a string 2015-12-23T16:43:58+01:00")

The condition v.to_s[/\d{4}\-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(Z|[+-]\d{2}:\d{2})/] allows it to continue to the parsing. DateTime parsing is "nice" enough to detect this situation and the string gets parsed and converted to the DateTime that contains, in my case the parsing was raising a "invalid date" exception because the string also had some weird data. In any case, I don't think we should parse the content in this situation. What do you think?

Hope you like my solution!

Cheers,

Julia

yukideluxe commented 8 years ago

I also think that Dates should get parsed too, what do you think? I can change the PR and handle the parsing like here https://github.com/whichdigital/active-rest-client/blob/master/lib/active_rest_client/base.rb#L27-L30

andyjeffries commented 8 years ago

@yukideluxe I think ActiveRestClient is pretty much abandonware. As the original author of most of the code, I forked it earlier this year to https://github.com/andyjeffries/flexirest. There have been a few fixes and new features since the fork (and nothing new this side). If you want to see if your change is still necessary and if so, raise it as a PR on there I'll see about accepting it.

andyjeffries commented 8 years ago

I think this may have been fixed within https://github.com/andyjeffries/flexirest/pull/8 ?