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:
parent
d43d8b912b
commit
2ce7185c8e
3 changed files with 18 additions and 0 deletions
|
@ -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) ##
|
## Rails 5.0.0 (June 30, 2016) ##
|
||||||
|
|
||||||
* Support parsing JSON time in ISO8601 local time strings in
|
* Support parsing JSON time in ISO8601 local time strings in
|
||||||
|
|
|
@ -447,6 +447,7 @@ module ActiveSupport
|
||||||
|
|
||||||
private
|
private
|
||||||
def parts_to_time(parts, now)
|
def parts_to_time(parts, now)
|
||||||
|
raise ArgumentError, "invalid date" if parts.nil?
|
||||||
return if parts.empty?
|
return if parts.empty?
|
||||||
|
|
||||||
time = Time.new(
|
time = Time.new(
|
||||||
|
|
|
@ -388,6 +388,13 @@ class TimeZoneTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
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
|
def test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize
|
||||||
tzinfo = TZInfo::Timezone.get('America/New_York')
|
tzinfo = TZInfo::Timezone.get('America/New_York')
|
||||||
zone = ActiveSupport::TimeZone.create(tzinfo.name, nil, tzinfo)
|
zone = ActiveSupport::TimeZone.create(tzinfo.name, nil, tzinfo)
|
||||||
|
|
Loading…
Reference in a new issue