1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #25793 from jmondo/strptime

Raise ArgumentError for bad strptime arguments
This commit is contained in:
Rafael França 2016-07-12 03:07:22 -03:00 committed by Rafael Mendonça França
parent d43d8b912b
commit 2ce7185c8e
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
3 changed files with 18 additions and 0 deletions

View file

@ -1,3 +1,13 @@
* 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*
## Rails 5.0.0 (June 30, 2016) ##
* Support parsing JSON time in ISO8601 local time strings in

View file

@ -447,6 +447,7 @@ module ActiveSupport
private
def parts_to_time(parts, now)
raise ArgumentError, "invalid date" if parts.nil?
return if parts.empty?
time = Time.new(

View file

@ -388,6 +388,13 @@ class TimeZoneTest < ActiveSupport::TestCase
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)