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

No-op Object#untaint to suppress deprecation warning in Ruby 2.7 #109

Merged
merged 1 commit into from Dec 9, 2019
Merged
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
5 changes: 5 additions & 0 deletions lib/tzinfo/data_sources/zoneinfo_data_source.rb
@@ -1,6 +1,11 @@
# encoding: UTF-8
# frozen_string_literal: true

if RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.7'
require 'tzinfo/untaint_ext'
using TZInfo::UntaintExt
end

module TZInfo
module DataSources
# An {InvalidZoneinfoDirectory} exception is raised if {ZoneinfoDataSource}
Expand Down
5 changes: 5 additions & 0 deletions lib/tzinfo/data_sources/zoneinfo_reader.rb
@@ -1,6 +1,11 @@
# encoding: UTF-8
# frozen_string_literal: true

if RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.7'
require 'tzinfo/untaint_ext'
using TZInfo::UntaintExt
end

module TZInfo
module DataSources
# An {InvalidZoneinfoFile} exception is raised if an attempt is made to load
Expand Down
12 changes: 12 additions & 0 deletions lib/tzinfo/untaint_ext.rb
@@ -0,0 +1,12 @@
# encoding: UTF-8
# frozen_string_literal: true

module TZInfo
module UntaintExt # :nodoc:
refine Object do
def untaint
self
end
end
end
end
12 changes: 6 additions & 6 deletions test/data_sources/tc_zoneinfo_reader.rb
Expand Up @@ -1216,10 +1216,10 @@ def test_read_untainted_in_safe_mode
o0 = TimezoneOffset.new(-12094, 0, 'LT')

tzif_test(offsets, []) do |path, format|
# Temp file path is tainted with Ruby >= 2.3.0. Untaint for this test.
path.untaint

safe_test do
# Temp file path is tainted with Ruby >= 2.3.0. Untaint for this test.
path.untaint

assert_equal(o0, @reader.read(path))
end
end
Expand All @@ -1229,10 +1229,10 @@ def test_read_tainted_in_safe_mode
offsets = [{gmtoff: -12094, isdst: false, abbrev: 'LT'}]

tzif_test(offsets, []) do |path, format|
# Temp file path is only tainted with Ruby >= 2.3.0. Taint for this test.
path.taint

safe_test(unavailable: :skip) do
# Temp file path is only tainted with Ruby >= 2.3.0. Taint for this test.
path.taint

assert_raises(SecurityError) { @reader.read(path) }
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_utils.rb
Expand Up @@ -289,8 +289,8 @@ def safe_test(options = {})
# JRuby, Rubinius and TruffleRuby don't support SAFE levels.
available = !%w(jruby rbx truffleruby).include?(RUBY_ENGINE)

if !available && options[:unavailable] == :skip
skip('JRuby, Rubinius and TruffleRuby don\'t support SAFE levels')
if !available && options[:unavailable] == :skip || RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.7'
skip('Ruby >= 2.7, JRuby, Rubinius and TruffleRuby don\'t support SAFE levels')
end

thread = Thread.new do
Expand Down