Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ruby 2.7 warnings for the 1.2 branch #111

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -16,6 +16,7 @@ rvm:
- 2.3.7
- 2.4.4
- 2.5.1
- 2.7.0
- ruby-head
- jruby-18mode
- jruby-1.7.27
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -3,6 +3,6 @@ source "https://rubygems.org"
gemspec

group :test do
gem 'rake', '~> 10.5'
gem 'rake', '~> 13.0'
gem 'minitest', '~> 5.0'
end
1 change: 1 addition & 0 deletions lib/tzinfo.rb
@@ -1,5 +1,6 @@
# Top level module for TZInfo.
module TZInfo
TAINT_SUPPORT = RUBY_VERSION <= '2.7'
end

require 'tzinfo/ruby_core_support'
Expand Down
7 changes: 5 additions & 2 deletions lib/tzinfo/ruby_core_support.rb
Expand Up @@ -138,8 +138,11 @@ def self.open_file(file_name, mode, opts, &block)
File.open(file_name, mode, &block)
end
else
def self.open_file(file_name, mode, opts, &block)
File.open(file_name, mode, opts, &block)
class << self
def open_file(file_name, mode, opts, &block)
::File.open(file_name, mode, opts, &block)
end
ruby2_keywords :open_file if respond_to?(:ruby2_keywords, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/Users/kamipo/src/github.com/rails/rails/vendor/bundle/ruby/2.7.0/bundler/gems/tzinfo-71873adbf908/lib/tzinfo/ruby_core_support.rb:145: warning: Skipping set of ruby2_keywords flag for open_file (method accepts keywords or method does not accept argument splat)

We can only use ruby2_keywords when method accepts splat arguments.
In this case probably we need extra version check RUBY_VERSION >= '2.0' then ::File.open(file_name, mode, **opts, &block).

end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tzinfo/ruby_data_source.rb
Expand Up @@ -26,7 +26,7 @@ def load_timezone_info(identifier)
# Untaint identifier after it has been reassigned to a new string. We
# don't want to modify the original identifier. identifier may also be
# frozen and therefore cannot be untainted.
identifier.untaint
identifier.untaint if TAINT_SUPPORT

identifier = identifier.split('/')
begin
Expand Down
4 changes: 2 additions & 2 deletions lib/tzinfo/zoneinfo_data_source.rb
Expand Up @@ -197,7 +197,7 @@ def load_timezone_info(identifier)
# Untaint path rather than identifier. We don't want to modify
# identifier. identifier may also be frozen and therefore cannot be
# untainted.
path.untaint
path.untaint if TAINT_SUPPORT

begin
ZoneinfoTimezoneInfo.new(identifier, path)
Expand Down Expand Up @@ -364,7 +364,7 @@ def load_timezone_index
def enum_timezones(dir, exclude = [], &block)
Dir.foreach(dir ? File.join(@zoneinfo_dir, dir) : @zoneinfo_dir) do |entry|
unless entry =~ /\./ || exclude.include?(entry)
entry.untaint
entry.untaint if TAINT_SUPPORT
path = dir ? File.join(dir, entry) : entry
full_path = File.join(@zoneinfo_dir, path)

Expand Down
2 changes: 1 addition & 1 deletion lib/tzinfo/zoneinfo_timezone_info.rb
Expand Up @@ -160,7 +160,7 @@ def define_offset(index, offset)
std_offset = 0
end

offset index, utc_offset, std_offset, offset[:abbr].untaint.to_sym
offset index, utc_offset, std_offset, offset[:abbr].to_sym
end

# Parses a zoneinfo file and intializes the DataTimezoneInfo structures.
Expand Down
7 changes: 5 additions & 2 deletions test/test_utils.rb
@@ -1,4 +1,7 @@
TESTS_DIR = File.expand_path(File.dirname(__FILE__)).untaint
test_dir = File.expand_path(File.dirname(__FILE__))
test_dir.untaint if RUBY_VERSION <= '2.7'
TESTS_DIR = test_dir

TZINFO_LIB_DIR = File.expand_path(File.join(TESTS_DIR, '..', 'lib'))
TZINFO_TEST_DATA_DIR = File.join(TESTS_DIR, 'tzinfo-data')
TZINFO_TEST_ZONEINFO_DIR = File.join(TESTS_DIR, 'zoneinfo')
Expand Down Expand Up @@ -56,7 +59,7 @@ def without_warnings

def safe_test(options = {})
# JRuby and Rubinus don't support SAFE levels.
available = !(defined?(RUBY_ENGINE) && %w(jruby rbx).include?(RUBY_ENGINE))
available = !(defined?(RUBY_ENGINE) && %w(jruby rbx).include?(RUBY_ENGINE)) && RUBY_VERSION < '2.7'

if available || options[:unavailable] != :skip
thread = Thread.new do
Expand Down