diff options
author | blackst0ne <blackst0ne.ru@gmail.com> | 2018-04-29 10:10:36 +1100 |
---|---|---|
committer | blackst0ne <blackst0ne.ru@gmail.com> | 2018-04-29 10:10:36 +1100 |
commit | b26a3f91b801c77db21f87a796943b862df3621d (patch) | |
tree | fed90884136fb172690976f207ca5e1645e17c14 | |
parent | ee189fd511e1a2c06f05e0d40e1d0b8875151391 (diff) | |
download | gitlab-ce-b26a3f91b801c77db21f87a796943b862df3621d.tar.gz |
[Rails5] Fix TZInfo::InvalidTimezoneIdentifier exception
In Rails 4.2.10 the `ActiveSupport::TimeZone.find_tzinfo(timezone_name)`
method calls `TZInfo::TimezoneProxy.new(timezone_name)` which returns
`timezone_name` if it is invalid.
But in Rails 5.0 the `ActiveSupport::TimeZone.find_tzinfo(timezone_name)`
method now calls the `TZInfo::Timezone.new(timezone_name)` method which
throws the `TZInfo::InvalidTimezoneIdentifier: Invalid identifier`
exception if `timezone_name` is invalid.
This commit adds the rescue block to return timezone name if the
exception is raised.
Also this change fixes the error:
```
1) Ci::PipelineSchedule validations does not allow invalid cron patters
Failure/Error: ActiveSupport::TimeZone.find_tzinfo(timezone).name
TZInfo::InvalidTimezoneIdentifier:
Invalid identifier
# ./lib/gitlab/ci/cron_parser.rb:28:in `timezone_name'
# ./lib/gitlab/ci/cron_parser.rb:9:in `initialize'
# ./app/validators/cron_validator.rb:6:in `new'
# ./app/validators/cron_validator.rb:6:in `validate_each'
# ./spec/models/ci/pipeline_schedule_spec.rb:26:in `block (3 levels) in <top (required)>'
```
-rw-r--r-- | lib/gitlab/ci/cron_parser.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/gitlab/ci/cron_parser.rb b/lib/gitlab/ci/cron_parser.rb index 551483d0aaa..73f36735e35 100644 --- a/lib/gitlab/ci/cron_parser.rb +++ b/lib/gitlab/ci/cron_parser.rb @@ -6,7 +6,7 @@ module Gitlab def initialize(cron, cron_timezone = 'UTC') @cron = cron - @cron_timezone = ActiveSupport::TimeZone.find_tzinfo(cron_timezone).name + @cron_timezone = timezone_name(cron_timezone) end def next_time_from(time) @@ -24,6 +24,12 @@ module Gitlab private + def timezone_name(timezone) + ActiveSupport::TimeZone.find_tzinfo(timezone).name + rescue TZInfo::InvalidTimezoneIdentifier + timezone + end + # NOTE: # cron_timezone can only accept timezones listed in TZInfo::Timezone. # Aliases of Timezones from ActiveSupport::TimeZone are NOT accepted, |