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
ActiveSupport::TimeZone.strptime has an empty? for nil exception #25701
Comments
Standard ruby version of > Date.strptime("2016-09-15", "%Y-%d-%m")
ArgumentError: invalid date
> DateTime.strptime("2014-04-13 21:20:50", "%m/%d/%Y")
ArgumentError: invalid date |
ArgumentError would be fine. The current error is due to a coding problem / bug ( module ActiveSupport
class TimeZone
private
def parts_to_time(parts, now)
return if parts.empty?
# …
end
end
end The exception coming out of ActiveSupport does not give an application developer any indication of the actual problem and loses the "malformed string / unmatching format" indication due to the nil handling issue. |
@nbibler are you working on this? if not, I'd be happy to submit a PR. I've been working my way through ActiveSupport as part of a learning exercise and fixing this bug would help my learning! LMK |
You're welcome to go for it. I imagine it'll be straightforward. Worst case, it's just a |
Sweet. Yep I think so too :) |
Steps to reproduce
Parse an ActiveSupport::TimeZone using
strptime
with a malformed string.Yields:
Expected behavior
It should either raise a reasonable exception or return
nil
.Actual behavior
It raises a
NoMethodError: undefined method empty? for nil:NilClass
.System configuration
Rails version: 4.2.6, 5.0.0
Ruby version: 2.1.8, 2.3.1
The text was updated successfully, but these errors were encountered: