提交 424e961b 编写于 作者: J John Gesimondo

Raise ArgumentError for bad strptime arguments

上级 108a407b
* 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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册