Raise ArgumentError for bad strptime arguments
This commit is contained in:
parent
108a407b7d
commit
424e961be7
@ -1,3 +1,12 @@
|
||||
* Fix `ActiveSupport::TimeZone#strptime`. Now raises `ArgumentError` when the
|
||||
given time doesn't match the format. The error is the same as the one given
|
||||
by Ruby's `Date.strptime`. Previously it raised
|
||||
`NoMethodError: undefined method empty? for nil:NilClass.` due to a bug.
|
||||
|
||||
Fixes #25701.
|
||||
|
||||
*John Gesimondo*
|
||||
|
||||
* `travel/travel_to` travel time helpers, now raise on nested calls,
|
||||
as this can lead to confusing time stubbing.
|
||||
|
||||
|
@ -447,6 +447,7 @@ def encode_with(coder) #:nodoc:
|
||||
|
||||
private
|
||||
def parts_to_time(parts, now)
|
||||
raise ArgumentError, "invalid date" if parts.nil?
|
||||
return if parts.empty?
|
||||
|
||||
time = Time.new(
|
||||
|
@ -388,6 +388,13 @@ def test_strptime_with_day_omitted
|
||||
end
|
||||
end
|
||||
|
||||
def test_strptime_with_malformed_string
|
||||
with_env_tz 'US/Eastern' do
|
||||
zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
|
||||
assert_raise(ArgumentError) { zone.strptime('1999-12-31', '%Y/%m/%d') }
|
||||
end
|
||||
end
|
||||
|
||||
def test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize
|
||||
tzinfo = TZInfo::Timezone.get('America/New_York')
|
||||
zone = ActiveSupport::TimeZone.create(tzinfo.name, nil, tzinfo)
|
||||
|
Loading…
Reference in New Issue
Block a user