Skip to content

Commit

Permalink
No-op Object#untaint to suppress deprecation warning in Ruby 2.7
Browse files Browse the repository at this point in the history
The Ruby core team decided to deprecate the taint mechanism in Ruby 2.7
and will remove that in Ruby 3.

https://bugs.ruby-lang.org/issues/16131
ruby/ruby#2476

This is an alternative of #108.
  • Loading branch information
kamipo committed Nov 24, 2019
1 parent 8fdf06e commit 3348dae
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
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

0 comments on commit 3348dae

Please sign in to comment.