diff options
author | David RodrÃguez <[email protected]> | 2023-10-26 22:11:34 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2023-11-13 11:06:10 +0900 |
commit | 54511303a46901a82e9b2d4ee460b2048e59a2e5 (patch) | |
tree | 3a465cce48ee0228b455a6810ac8cc026b1bded2 | |
parent | 435eb56f6175b7c9a16121ec8441f7492fa9aec5 (diff) |
[rubygems/rubygems] Drop support for Ruby 2.6 and Ruby 2.7 in RubyGems
https://github.com/rubygems/rubygems/commit/10c26a483d
24 files changed, 37 insertions, 90 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 5657dc3fbf..ffbd87af7d 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -115,11 +115,6 @@ require_relative "rubygems/errors" module Gem RUBYGEMS_DIR = __dir__ - # Taint support is deprecated in Ruby 2.7. - # This allows switching ".untaint" to ".tap(&Gem::UNTAINT)", - # to avoid deprecation warnings in Ruby 2.7. - UNTAINT = RUBY_VERSION < "2.7" ? :untaint.to_sym : proc {} - ## # An Array of Regexps that match windows Ruby platforms. @@ -496,7 +491,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} glob_with_suffixes = "#{glob}#{Gem.suffix_pattern}" $LOAD_PATH.map do |load_path| Gem::Util.glob_files_in_dir(glob_with_suffixes, load_path) - end.flatten.select {|file| File.file? file.tap(&Gem::UNTAINT) } + end.flatten.select {|file| File.file? file } end ## @@ -1084,8 +1079,6 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} end end - path.tap(&Gem::UNTAINT) - unless File.file? path return unless raise_exception @@ -1352,7 +1345,7 @@ require_relative "rubygems/core_ext/kernel_gem" path = File.join(__dir__, "rubygems/core_ext/kernel_require.rb") # When https://bugs.ruby-lang.org/issues/17259 is available, there is no need to override Kernel#warn if RUBY_ENGINE == "truffleruby" || - (RUBY_ENGINE == "ruby" && RUBY_VERSION >= "3.0") + RUBY_ENGINE == "ruby" file = "<internal:#{path}>" else require_relative "rubygems/core_ext/kernel_warn" diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index 6246737847..03fd07d284 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -96,7 +96,7 @@ class Gem::BasicSpecification # Returns full path to the directory where gem's extensions are installed. def extension_dir - @extension_dir ||= File.expand_path(File.join(extensions_dir, full_name)).tap(&Gem::UNTAINT) + @extension_dir ||= File.expand_path(File.join(extensions_dir, full_name)) end ## @@ -110,9 +110,7 @@ class Gem::BasicSpecification def find_full_gem_path # :nodoc: # TODO: also, shouldn't it default to full_name if it hasn't been written? - path = File.expand_path File.join(gems_dir, full_name) - path.tap(&Gem::UNTAINT) - path + File.expand_path File.join(gems_dir, full_name) end private :find_full_gem_path @@ -133,9 +131,9 @@ class Gem::BasicSpecification def full_name if platform == Gem::Platform::RUBY || platform.nil? - (+"#{name}-#{version}").tap(&Gem::UNTAINT) + +"#{name}-#{version}" else - (+"#{name}-#{version}-#{platform}").tap(&Gem::UNTAINT) + +"#{name}-#{version}-#{platform}" end end @@ -147,7 +145,7 @@ class Gem::BasicSpecification @full_require_paths ||= begin full_paths = raw_require_paths.map do |path| - File.join full_gem_path, path.tap(&Gem::UNTAINT) + File.join full_gem_path, path end full_paths << extension_dir if have_extensions? @@ -161,7 +159,7 @@ class Gem::BasicSpecification def datadir # TODO: drop the extra ", gem_name" which is uselessly redundant - File.expand_path(File.join(gems_dir, full_name, "data", name)).tap(&Gem::UNTAINT) + File.expand_path(File.join(gems_dir, full_name, "data", name)) end ## @@ -270,7 +268,7 @@ class Gem::BasicSpecification def matches_for_glob(glob) # TODO: rename? glob = File.join(lib_dirs_glob, glob) - Dir[glob].map {|f| f.tap(&Gem::UNTAINT) } # FIX our tests are broken, run w/ SAFE=1 + Dir[glob] end ## @@ -295,7 +293,7 @@ class Gem::BasicSpecification "lib" # default value for require_paths for bundler/inline end - "#{full_gem_path}/#{dirs}".dup.tap(&Gem::UNTAINT) + "#{full_gem_path}/#{dirs}".dup end ## @@ -332,7 +330,7 @@ class Gem::BasicSpecification def have_file?(file, suffixes) return true if raw_require_paths.any? do |path| - base = File.join(gems_dir, full_name, path.tap(&Gem::UNTAINT), file).tap(&Gem::UNTAINT) + base = File.join(gems_dir, full_name, path, file) suffixes.any? {|suf| File.file? base + suf } end diff --git a/lib/rubygems/bundler_version_finder.rb b/lib/rubygems/bundler_version_finder.rb index cd51c37c59..14a4adf029 100644 --- a/lib/rubygems/bundler_version_finder.rb +++ b/lib/rubygems/bundler_version_finder.rb @@ -52,7 +52,7 @@ module Gem::BundlerVersionFinder unless gemfile begin Gem::Util.traverse_parents(Dir.pwd) do |directory| - next unless gemfile = Gem::GEM_DEP_FILES.find {|f| File.file?(f.tap(&Gem::UNTAINT)) } + next unless gemfile = Gem::GEM_DEP_FILES.find {|f| File.file?(f) } gemfile = File.join directory, gemfile break @@ -67,7 +67,7 @@ module Gem::BundlerVersionFinder lockfile = case gemfile when "gems.rb" then "gems.locked" else "#{gemfile}.lock" - end.dup.tap(&Gem::UNTAINT) + end.dup return unless File.file?(lockfile) diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index fb27e755bc..6d3597fb56 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -328,12 +328,8 @@ command to remove old versions. @oldest_supported_version ||= if Gem.ruby_version > Gem::Version.new("3.1.a") Gem::Version.new("3.3.3") - elsif Gem.ruby_version > Gem::Version.new("3.0.a") - Gem::Version.new("3.2.3") - elsif Gem.ruby_version > Gem::Version.new("2.7.a") - Gem::Version.new("3.1.2") else - Gem::Version.new("3.0.1") + Gem::Version.new("3.2.3") end end end diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index d90ec9f92c..5d4dcacb2f 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -188,7 +188,7 @@ class Gem::ConfigFile operating_system_config = Marshal.load Marshal.dump(OPERATING_SYSTEM_DEFAULTS) platform_config = Marshal.load Marshal.dump(PLATFORM_DEFAULTS) system_config = load_file SYSTEM_WIDE_CONFIG_FILE - user_config = load_file config_file_name.dup.tap(&Gem::UNTAINT) + user_config = load_file config_file_name.dup environment_config = (ENV["GEMRC"] || ""). split(File::PATH_SEPARATOR).inject({}) do |result, file| diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb index ddb44276eb..a72b55a2da 100644 --- a/lib/rubygems/core_ext/kernel_require.rb +++ b/lib/rubygems/core_ext/kernel_require.rb @@ -46,7 +46,7 @@ module Kernel load_path_check_index = Gem.load_path_insert_index - Gem.activated_gem_paths Gem.suffixes.find do |s| $LOAD_PATH[0...load_path_check_index].find do |lp| - safe_lp = lp.dup.tap(&Gem::UNTAINT) + safe_lp = lp.dup if File.symlink? safe_lp # for backward compatibility next end diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb index 7888e8cee5..1fe6f36f38 100644 --- a/lib/rubygems/defaults.rb +++ b/lib/rubygems/defaults.rb @@ -94,7 +94,7 @@ module Gem # The home directory for the user. def self.user_home - @user_home ||= find_home.tap(&Gem::UNTAINT) + @user_home ||= find_home end ## @@ -131,14 +131,14 @@ module Gem # The path to standard location of the user's .gemrc file. def self.config_file - @config_file ||= find_config_file.tap(&Gem::UNTAINT) + @config_file ||= find_config_file end ## # The path to standard location of the user's state file. def self.state_file - @state_file ||= File.join(Gem.state_home, "gem", "last_update_check").tap(&Gem::UNTAINT) + @state_file ||= File.join(Gem.state_home, "gem", "last_update_check") end ## diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 26a69a1f05..b5644c36b7 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -390,7 +390,7 @@ class Gem::Installer specs = [] Gem::Util.glob_files_in_dir("*.gemspec", File.join(gem_home, "specifications")).each do |path| - spec = Gem::Specification.load path.tap(&Gem::UNTAINT) + spec = Gem::Specification.load path specs << spec if spec end @@ -489,7 +489,6 @@ class Gem::Installer ensure_writable_dir @bin_dir spec.executables.each do |filename| - filename.tap(&Gem::UNTAINT) bin_path = File.join gem_dir, spec.bindir, filename next unless File.exist? bin_path @@ -631,7 +630,6 @@ class Gem::Installer def ensure_loadable_spec ruby = spec.to_ruby_for_cache - ruby.tap(&Gem::UNTAINT) begin eval ruby diff --git a/lib/rubygems/name_tuple.rb b/lib/rubygems/name_tuple.rb index 2a8f397481..206083dc2f 100644 --- a/lib/rubygems/name_tuple.rb +++ b/lib/rubygems/name_tuple.rb @@ -51,7 +51,7 @@ class Gem::NameTuple "#{@name}-#{@version}" else "#{@name}-#{@version}-#{@platform}" - end.dup.tap(&Gem::UNTAINT) + end.dup end ## diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index 5dcc3ce858..7fc639a60b 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -512,7 +512,6 @@ EOM raise Gem::Package::PathError.new(destination, destination_dir) unless normalize_path(destination).start_with? normalize_path(destination_dir + "/") - destination.tap(&Gem::UNTAINT) destination end diff --git a/lib/rubygems/path_support.rb b/lib/rubygems/path_support.rb index b966e15f9c..bde9ce2bde 100644 --- a/lib/rubygems/path_support.rb +++ b/lib/rubygems/path_support.rb @@ -48,7 +48,7 @@ class Gem::PathSupport @spec_cache_dir = env["GEM_SPEC_CACHE"] || Gem.default_spec_cache_dir - @spec_cache_dir = @spec_cache_dir.dup.tap(&Gem::UNTAINT) + @spec_cache_dir = @spec_cache_dir.dup end private diff --git a/lib/rubygems/request_set.rb b/lib/rubygems/request_set.rb index 46e9cc346c..d0a8d6081c 100644 --- a/lib/rubygems/request_set.rb +++ b/lib/rubygems/request_set.rb @@ -324,7 +324,7 @@ class Gem::RequestSet @git_set.root_dir = @install_dir - lock_file = "#{File.expand_path(path)}.lock".dup.tap(&Gem::UNTAINT) + lock_file = "#{File.expand_path(path)}.lock".dup begin tokenizer = Gem::RequestSet::Lockfile::Tokenizer.from_file lock_file parser = tokenizer.make_parser self, [] diff --git a/lib/rubygems/request_set/gem_dependency_api.rb b/lib/rubygems/request_set/gem_dependency_api.rb index 28e232cfd3..698da378b5 100644 --- a/lib/rubygems/request_set/gem_dependency_api.rb +++ b/lib/rubygems/request_set/gem_dependency_api.rb @@ -280,7 +280,7 @@ class Gem::RequestSet::GemDependencyAPI # Loads the gem dependency file and returns self. def load - instance_eval File.read(@path).tap(&Gem::UNTAINT), @path, 1 + instance_eval File.read(@path), @path, 1 self end diff --git a/lib/rubygems/request_set/lockfile.rb b/lib/rubygems/request_set/lockfile.rb index 7b115fe59b..c446b3ae51 100644 --- a/lib/rubygems/request_set/lockfile.rb +++ b/lib/rubygems/request_set/lockfile.rb @@ -76,11 +76,6 @@ class Gem::RequestSet::Lockfile @dependencies = dependencies @gem_deps_file = File.expand_path(gem_deps_file) @gem_deps_dir = File.dirname(@gem_deps_file) - - if RUBY_VERSION < "2.7" - @gem_deps_file.untaint unless gem_deps_file.tainted? - end - @platforms = [] end diff --git a/lib/rubygems/source.rb b/lib/rubygems/source.rb index 7c5b746a43..5a51e22787 100644 --- a/lib/rubygems/source.rb +++ b/lib/rubygems/source.rb @@ -101,7 +101,6 @@ class Gem::Source def cache_dir(uri) # Correct for windows paths escaped_path = uri.path.sub(%r{^/([a-z]):/}i, '/\\1-/') - escaped_path.tap(&Gem::UNTAINT) File.join Gem.spec_cache_dir, "#{uri.host}%#{uri.port}", File.dirname(escaped_path) end diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 31ef29f02f..b3ebfbaa7a 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -783,7 +783,7 @@ class Gem::Specification < Gem::BasicSpecification def self.each_gemspec(dirs) # :nodoc: dirs.each do |dir| Gem::Util.glob_files_in_dir("*.gemspec", dir).each do |path| - yield path.tap(&Gem::UNTAINT) + yield path end end end @@ -969,7 +969,7 @@ class Gem::Specification < Gem::BasicSpecification def self.dirs @@dirs ||= Gem.path.collect do |dir| - File.join dir.dup.tap(&Gem::UNTAINT), "specifications" + File.join dir.dup, "specifications" end end @@ -1162,13 +1162,11 @@ class Gem::Specification < Gem::BasicSpecification spec = @load_cache_mutex.synchronize { @load_cache[file] } return spec if spec - file = file.dup.tap(&Gem::UNTAINT) + file = file.dup return unless File.file?(file) code = Gem.open_file(file, "r:UTF-8:-", &:read) - code.tap(&Gem::UNTAINT) - begin spec = eval code, binding, file @@ -2702,9 +2700,9 @@ class Gem::Specification < Gem::BasicSpecification case ivar when "date" # Force Date to go through the extra coerce logic in date= - self.date = val.tap(&Gem::UNTAINT) + self.date = val else - instance_variable_set "@#{ivar}", val.tap(&Gem::UNTAINT) + instance_variable_set "@#{ivar}", val end end diff --git a/lib/rubygems/stub_specification.rb b/lib/rubygems/stub_specification.rb index 5953db0d64..58748df5d6 100644 --- a/lib/rubygems/stub_specification.rb +++ b/lib/rubygems/stub_specification.rb @@ -69,7 +69,6 @@ class Gem::StubSpecification < Gem::BasicSpecification def initialize(filename, base_dir, gems_dir, default_gem) super() - filename.tap(&Gem::UNTAINT) self.loaded_from = filename @data = nil diff --git a/test/rubygems/bundler_test_gem.rb b/test/rubygems/bundler_test_gem.rb index 78adfc94c5..319112bac8 100644 --- a/test/rubygems/bundler_test_gem.rb +++ b/test/rubygems/bundler_test_gem.rb @@ -3,7 +3,7 @@ require_relative "helper" class TestBundlerGem < Gem::TestCase - PROJECT_DIR = File.expand_path("../..", __dir__).tap(&Gem::UNTAINT) + PROJECT_DIR = File.expand_path("../..", __dir__) def test_self_use_gemdeps with_local_bundler_at(Gem.dir) do @@ -221,7 +221,7 @@ class TestBundlerGem < Gem::TestCase def test_use_gemdeps with_local_bundler_at(Gem.dir) do - gem_deps_file = "gem.deps.rb".tap(&Gem::UNTAINT) + gem_deps_file = "gem.deps.rb" spec = util_spec "a", 1 install_specs spec diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index b55e526d77..d04ed3dc8e 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -295,7 +295,6 @@ class Gem::TestCase < Test::Unit::TestCase FileUtils.mkdir_p @tmp @tempdir = Dir.mktmpdir("test_rubygems_", @tmp) - @tempdir.tap(&Gem::UNTAINT) ENV["GEM_VENDOR"] = nil ENV["GEMRC"] = nil @@ -345,7 +344,6 @@ class Gem::TestCase < Test::Unit::TestCase File.expand_path(s) end if expand_path != s - expand_path.tap(&Gem::UNTAINT) if s.instance_variable_defined?(:@gem_prelude_index) expand_path.instance_variable_set(:@gem_prelude_index, expand_path) end @@ -606,7 +604,7 @@ class Gem::TestCase < Test::Unit::TestCase end end - gem = File.join(@tempdir, File.basename(gem)).tap(&Gem::UNTAINT) + gem = File.join(@tempdir, File.basename(gem)) end Gem::Installer.at(gem, options.merge({ :wrappers => true })).install @@ -645,7 +643,7 @@ class Gem::TestCase < Test::Unit::TestCase # Reads a Marshal file at +path+ def read_cache(path) - File.open path.dup.tap(&Gem::UNTAINT), "rb" do |io| + File.open path.dup, "rb" do |io| Marshal.load io.read end end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index a7174cf689..6537afad2a 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -11,7 +11,7 @@ require "rbconfig" class TestGem < Gem::TestCase PLUGINS_LOADED = [] # rubocop:disable Style/MutableConstant - PROJECT_DIR = File.expand_path("../..", __dir__).tap(&Gem::UNTAINT) + PROJECT_DIR = File.expand_path("../..", __dir__) def setup super @@ -201,7 +201,7 @@ class TestGem < Gem::TestCase end assert_equal(expected, result) ensure - File.chmod(0o755, *Dir.glob(@gemhome + "/gems/**/").map {|path| path.tap(&Gem::UNTAINT) }) + File.chmod(0o755, *Dir.glob(@gemhome + "/gems/**/")) end def test_require_missing diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb index fe7f3da137..f04ec0cafa 100644 --- a/test/rubygems/test_gem_command_manager.rb +++ b/test/rubygems/test_gem_command_manager.rb @@ -4,7 +4,7 @@ require_relative "helper" require "rubygems/command_manager" class TestGemCommandManager < Gem::TestCase - PROJECT_DIR = File.expand_path("../..", __dir__).tap(&Gem::UNTAINT) + PROJECT_DIR = File.expand_path("../..", __dir__) def setup super diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb index 68dbf119a4..2065864107 100644 --- a/test/rubygems/test_gem_package.rb +++ b/test/rubygems/test_gem_package.rb @@ -760,12 +760,10 @@ class TestGemPackage < Gem::Package::TarTestCase package = Gem::Package.new @gem file = "file.rb".dup - file.taint if RUBY_VERSION < "2.7" destination = package.install_location file, @destination assert_equal File.join(@destination, "file.rb"), destination - refute destination.tainted? if RUBY_VERSION < "2.7" end def test_install_location_absolute @@ -799,12 +797,10 @@ class TestGemPackage < Gem::Package::TarTestCase package = Gem::Package.new @gem file = "foo//file.rb".dup - file.taint if RUBY_VERSION < "2.7" destination = package.install_location file, @destination assert_equal File.join(@destination, "foo", "file.rb"), destination - refute destination.tainted? if RUBY_VERSION < "2.7" end def test_install_location_relative diff --git a/test/rubygems/test_gem_safe_marshal.rb b/test/rubygems/test_gem_safe_marshal.rb index 362e5e00ad..29685f458c 100644 --- a/test/rubygems/test_gem_safe_marshal.rb +++ b/test/rubygems/test_gem_safe_marshal.rb @@ -212,7 +212,7 @@ class TestGemSafeMarshal < Gem::TestCase Time.at(secs, 1.00001, :nanosecond), Time.at(secs, 1.00001, :nanosecond), ].tap do |times| - unless RUBY_ENGINE == "truffleruby" && RUBY_ENGINE_VERSION < "23" || RUBY_VERSION < "2.7" + unless RUBY_ENGINE == "truffleruby" && RUBY_ENGINE_VERSION < "23" times.concat [ Time.at(secs, in: "UTC"), Time.at(secs, in: "Z"), diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 8d86820c71..28697529ef 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -797,28 +797,6 @@ dependencies: [] assert_equal File.join(@tempdir, "a-2.gemspec"), spec.loaded_from end - if RUBY_ENGINE == "ruby" && RUBY_VERSION < "2.7" - def test_self_load_tainted - full_path = @a2.spec_file - write_file full_path do |io| - io.write @a2.to_ruby_for_cache - end - - full_path.taint - loader = Thread.new do - $SAFE = 1 - Gem::Specification.load full_path - end - spec = loader.value - - @a2.files.clear - - assert_equal @a2, spec - ensure - $SAFE = 0 - end - end - def test_self_load_escape_curly @a2.name = 'a};raise "improper escaping";%q{' |