From 7d463e360b9c4718b17378eb52783116a01b884b Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Mon, 11 Nov 2019 15:03:57 +0900 Subject: Merge RubyGems 3.1.0.pre3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix gem pristine not accounting for user installed gems. Pull request #2914 by Luis Sagastume. * Refactor keyword argument test for Ruby 2.7. Pull request #2947 by SHIBATA Hiroshi. * Fix errors at frozen Gem::Version. Pull request #2949 by Nobuyoshi Nakada. * Remove taint usage on Ruby 2.7+. Pull request #2951 by Jeremy Evans. * Check Manifest.txt is up to date. Pull request #2953 by David Rodríguez. * Clarify symlink conditionals in tests. Pull request #2962 by David Rodríguez. * Update command line parsing to work under ps. Pull request #2966 by David Rodríguez. * Properly test `Gem::Specifications.stub_for`. Pull request #2970 by David Rodríguez. * Fix Gem::LOADED_SPECS_MUTEX handling for recursive locking. Pull request #2985 by MSP-Greg. --- lib/rubygems/basic_specification.rb | 18 ++++++------ lib/rubygems/bundler_version_finder.rb | 4 +-- lib/rubygems/commands/pristine_command.rb | 5 ---- lib/rubygems/config_file.rb | 2 +- lib/rubygems/core_ext/kernel_gem.rb | 10 +++++-- lib/rubygems/core_ext/kernel_require.rb | 2 +- lib/rubygems/installer.rb | 8 ++---- lib/rubygems/name_tuple.rb | 2 +- lib/rubygems/package.rb | 2 +- lib/rubygems/path_support.rb | 2 +- lib/rubygems/request_set.rb | 2 +- lib/rubygems/request_set/gem_dependency_api.rb | 2 +- lib/rubygems/request_set/lockfile.rb | 4 ++- lib/rubygems/source.rb | 2 +- lib/rubygems/specification.rb | 12 ++++---- lib/rubygems/stub_specification.rb | 2 +- lib/rubygems/test_case.rb | 12 ++++---- lib/rubygems/version.rb | 38 ++++++++++++++++---------- 18 files changed, 68 insertions(+), 61 deletions(-) (limited to 'lib/rubygems') diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index 347f8c3318..c6d63ac473 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -98,7 +98,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)).untaint + @extension_dir ||= File.expand_path(File.join(extensions_dir, full_name)).tap(&Gem::UNTAINT) end ## @@ -113,7 +113,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.untaint + path.tap(&Gem::UNTAINT) path end @@ -135,9 +135,9 @@ class Gem::BasicSpecification def full_name if platform == Gem::Platform::RUBY or platform.nil? - "#{name}-#{version}".dup.untaint + "#{name}-#{version}".dup.tap(&Gem::UNTAINT) else - "#{name}-#{version}-#{platform}".dup.untaint + "#{name}-#{version}-#{platform}".dup.tap(&Gem::UNTAINT) end end @@ -149,7 +149,7 @@ class Gem::BasicSpecification @full_require_paths ||= begin full_paths = raw_require_paths.map do |path| - File.join full_gem_path, path.untaint + File.join full_gem_path, path.tap(&Gem::UNTAINT) end full_paths << extension_dir if have_extensions? @@ -163,7 +163,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)).untaint + File.expand_path(File.join(gems_dir, full_name, "data", name)).tap(&Gem::UNTAINT) end ## @@ -277,7 +277,7 @@ class Gem::BasicSpecification # TODO: do we need these?? Kill it glob = File.join(self.lib_dirs_glob, glob) - Dir[glob].map { |f| f.untaint } # FIX our tests are broken, run w/ SAFE=1 + Dir[glob].map { |f| f.tap(&Gem::UNTAINT) } # FIX our tests are broken, run w/ SAFE=1 end ## @@ -295,7 +295,7 @@ class Gem::BasicSpecification "lib" # default value for require_paths for bundler/inline end - "#{self.full_gem_path}/#{dirs}".dup.untaint + "#{self.full_gem_path}/#{dirs}".dup.tap(&Gem::UNTAINT) end ## @@ -328,7 +328,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.untaint, file).untaint + base = File.join(gems_dir, full_name, path.tap(&Gem::UNTAINT), file).tap(&Gem::UNTAINT) 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 7f420e6fea..38da7738a8 100644 --- a/lib/rubygems/bundler_version_finder.rb +++ b/lib/rubygems/bundler_version_finder.rb @@ -83,7 +83,7 @@ To install the missing version, run `gem install bundler:#{vr.first}` gemfile = ENV["BUNDLE_GEMFILE"] gemfile = nil if gemfile && gemfile.empty? Gem::Util.traverse_parents Dir.pwd do |directory| - next unless gemfile = Gem::GEM_DEP_FILES.find { |f| File.file?(f.untaint) } + next unless gemfile = Gem::GEM_DEP_FILES.find { |f| File.file?(f.tap(&Gem::UNTAINT)) } gemfile = File.join directory, gemfile break @@ -94,7 +94,7 @@ To install the missing version, run `gem install bundler:#{vr.first}` lockfile = case gemfile when "gems.rb" then "gems.locked" else "#{gemfile}.lock" - end.dup.untaint + end.dup.tap(&Gem::UNTAINT) return unless File.file?(lockfile) diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb index e4628bdd40..2248a821c8 100644 --- a/lib/rubygems/commands/pristine_command.rb +++ b/lib/rubygems/commands/pristine_command.rb @@ -111,11 +111,6 @@ extensions will be restored. "Failed to find gems #{options[:args]} #{options[:version]}" end - install_dir = Gem.dir # TODO use installer option - - raise Gem::FilePermissionError.new(install_dir) unless - File.writable?(install_dir) - say "Restoring gems to pristine condition..." specs.each do |spec| diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index 26e80afe24..54d8a9c152 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -180,7 +180,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.untaint + user_config = load_file config_file_name.dup.tap(&Gem::UNTAINT) environment_config = (ENV['GEMRC'] || '') .split(File::PATH_SEPARATOR).inject({}) do |result, file| diff --git a/lib/rubygems/core_ext/kernel_gem.rb b/lib/rubygems/core_ext/kernel_gem.rb index fb3053fd83..e722225739 100644 --- a/lib/rubygems/core_ext/kernel_gem.rb +++ b/lib/rubygems/core_ext/kernel_gem.rb @@ -61,9 +61,13 @@ module Kernel spec = dep.to_spec - Gem::LOADED_SPECS_MUTEX.synchronize do - spec.activate - end if spec + if spec + if Gem::LOADED_SPECS_MUTEX.owned? + spec.activate + else + Gem::LOADED_SPECS_MUTEX.synchronize { spec.activate } + end + end end private :gem diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb index 858f0998a0..f0409d6068 100644 --- a/lib/rubygems/core_ext/kernel_require.rb +++ b/lib/rubygems/core_ext/kernel_require.rb @@ -41,7 +41,7 @@ module Kernel resolved_path = begin rp = nil $LOAD_PATH[0...Gem.load_path_insert_index || -1].each do |lp| - safe_lp = lp.dup.untaint + safe_lp = lp.dup.tap(&Gem::UNTAINT) next if File.symlink? safe_lp # for backword compatibility Gem.suffixes.each do |s| full_path = File.expand_path(File.join(safe_lp, "#{path}#{s}")) diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 0ffddc52fc..ad39ec81bf 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -196,8 +196,6 @@ class Gem::Installer @package.prog_mode = options[:prog_mode] @package.data_mode = options[:data_mode] - @bin_dir = options[:bin_dir] if options[:bin_dir] - if options[:user_install] @gem_home = Gem.user_dir @bin_dir = Gem.bindir gem_home unless options[:bin_dir] @@ -394,7 +392,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.untaint + spec = Gem::Specification.load path.tap(&Gem::UNTAINT) specs << spec if spec end @@ -502,7 +500,7 @@ class Gem::Installer raise Gem::FilePermissionError.new(@bin_dir) unless File.writable? @bin_dir spec.executables.each do |filename| - filename.untaint + filename.tap(&Gem::UNTAINT) bin_path = File.join gem_dir, spec.bindir, filename unless File.exist? bin_path @@ -633,7 +631,7 @@ class Gem::Installer def ensure_loadable_spec ruby = spec.to_ruby_for_cache - ruby.untaint + ruby.tap(&Gem::UNTAINT) begin eval ruby diff --git a/lib/rubygems/name_tuple.rb b/lib/rubygems/name_tuple.rb index 7cb38233eb..dc1a1bbaa0 100644 --- a/lib/rubygems/name_tuple.rb +++ b/lib/rubygems/name_tuple.rb @@ -55,7 +55,7 @@ class Gem::NameTuple "#{@name}-#{@version}" else "#{@name}-#{@version}-#{@platform}" - end.dup.untaint + end.dup.tap(&Gem::UNTAINT) end ## diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index dadbf6a481..813ab9da33 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -498,7 +498,7 @@ EOM real_destination.start_with? destination_dir + '/' end - destination.untaint + destination.tap(&Gem::UNTAINT) destination end diff --git a/lib/rubygems/path_support.rb b/lib/rubygems/path_support.rb index 2187766c41..6a5d180a02 100644 --- a/lib/rubygems/path_support.rb +++ b/lib/rubygems/path_support.rb @@ -36,7 +36,7 @@ class Gem::PathSupport @spec_cache_dir = env["GEM_SPEC_CACHE"] || Gem.default_spec_cache_dir - @spec_cache_dir = @spec_cache_dir.dup.untaint + @spec_cache_dir = @spec_cache_dir.dup.tap(&Gem::UNTAINT) end private diff --git a/lib/rubygems/request_set.rb b/lib/rubygems/request_set.rb index 4ac6ce0293..d6fb41f514 100644 --- a/lib/rubygems/request_set.rb +++ b/lib/rubygems/request_set.rb @@ -334,7 +334,7 @@ class Gem::RequestSet @git_set.root_dir = @install_dir - lock_file = "#{File.expand_path(path)}.lock".dup.untaint + lock_file = "#{File.expand_path(path)}.lock".dup.tap(&Gem::UNTAINT) 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 cb36a62e10..b7a8ee6f4f 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).untaint, @path, 1 + instance_eval File.read(@path).tap(&Gem::UNTAINT), @path, 1 self end diff --git a/lib/rubygems/request_set/lockfile.rb b/lib/rubygems/request_set/lockfile.rb index 0776cf82e3..5423f2c14f 100644 --- a/lib/rubygems/request_set/lockfile.rb +++ b/lib/rubygems/request_set/lockfile.rb @@ -79,7 +79,9 @@ class Gem::RequestSet::Lockfile @gem_deps_file = File.expand_path(gem_deps_file) @gem_deps_dir = File.dirname(@gem_deps_file) - @gem_deps_file.untaint unless gem_deps_file.tainted? + 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 faed7bd350..b0cce5bea5 100644 --- a/lib/rubygems/source.rb +++ b/lib/rubygems/source.rb @@ -106,7 +106,7 @@ class Gem::Source def cache_dir(uri) # Correct for windows paths escaped_path = uri.path.sub(/^\/([a-z]):\//i, '/\\1-/') - escaped_path.untaint + 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 4fd556f193..5321edfcc3 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -763,7 +763,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.untaint + yield path.tap(&Gem::UNTAINT) end end end @@ -930,7 +930,7 @@ class Gem::Specification < Gem::BasicSpecification def self.dirs @@dirs ||= Gem.path.collect do |dir| - File.join dir.dup.untaint, "specifications" + File.join dir.dup.tap(&Gem::UNTAINT), "specifications" end end @@ -1112,12 +1112,12 @@ class Gem::Specification < Gem::BasicSpecification _spec = LOAD_CACHE_MUTEX.synchronize { LOAD_CACHE[file] } return _spec if _spec - file = file.dup.untaint + file = file.dup.tap(&Gem::UNTAINT) return unless File.file?(file) code = File.read file, :mode => 'r:UTF-8:-' - code.untaint + code.tap(&Gem::UNTAINT) begin _spec = eval code, binding, file @@ -2642,9 +2642,9 @@ class Gem::Specification < Gem::BasicSpecification case ivar when "date" # Force Date to go through the extra coerce logic in date= - self.date = val.untaint + self.date = val.tap(&Gem::UNTAINT) else - instance_variable_set "@#{ivar}", val.untaint + instance_variable_set "@#{ivar}", val.tap(&Gem::UNTAINT) end end diff --git a/lib/rubygems/stub_specification.rb b/lib/rubygems/stub_specification.rb index 2f3245f5d0..959030fd54 100644 --- a/lib/rubygems/stub_specification.rb +++ b/lib/rubygems/stub_specification.rb @@ -71,7 +71,7 @@ class Gem::StubSpecification < Gem::BasicSpecification def initialize(filename, base_dir, gems_dir, default_gem) super() - filename.untaint + filename.tap(&Gem::UNTAINT) self.loaded_from = filename @data = nil diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index 14212b9213..5ecf2ab1d8 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -259,10 +259,10 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni Gem::DefaultUserInteraction.ui = Gem::MockGemUi.new tmpdir = File.realpath Dir.tmpdir - tmpdir.untaint + tmpdir.tap(&Gem::UNTAINT) @tempdir = File.join(tmpdir, "test_rubygems_#{$$}") - @tempdir.untaint + @tempdir.tap(&Gem::UNTAINT) FileUtils.mkdir_p @tempdir @@ -274,7 +274,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni # Short and long path name is specific to Windows filesystem. if win_platform? @tempdir = Dir[@tempdir][0] - @tempdir.untaint + @tempdir.tap(&Gem::UNTAINT) end @gemhome = File.join @tempdir, 'gemhome' @@ -295,7 +295,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni $LOAD_PATH.map! do |s| expand_path = File.realpath(s) rescue File.expand_path(s) if expand_path != s - expand_path.untaint + expand_path.tap(&Gem::UNTAINT) if s.instance_variable_defined?(:@gem_prelude_index) expand_path.instance_variable_set(:@gem_prelude_index, expand_path) end @@ -527,7 +527,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni end end - gem = File.join(@tempdir, File.basename(spec.cache_file)).untaint + gem = File.join(@tempdir, File.basename(spec.cache_file)).tap(&Gem::UNTAINT) end Gem::Installer.at(gem, options.merge({:wrappers => true})).install @@ -566,7 +566,7 @@ class Gem::TestCase < (defined?(Minitest::Test) ? Minitest::Test : MiniTest::Uni # Reads a Marshal file at +path+ def read_cache(path) - File.open path.dup.untaint, 'rb' do |io| + File.open path.dup.tap(&Gem::UNTAINT), 'rb' do |io| Marshal.load io.read end end diff --git a/lib/rubygems/version.rb b/lib/rubygems/version.rb index 619f327968..6524faf5c8 100644 --- a/lib/rubygems/version.rb +++ b/lib/rubygems/version.rb @@ -197,6 +197,8 @@ class Gem::Version end @@all = {} + @@bump = {} + @@release = {} def self.new(version) # :nodoc: return super unless Gem::Version == self @@ -227,14 +229,14 @@ class Gem::Version # Pre-release (alpha) parts, e.g, 5.3.1.b.2 => 5.4, are ignored. def bump - @bump ||= begin - segments = self.segments - segments.pop while segments.any? { |s| String === s } - segments.pop if segments.size > 1 - - segments[-1] = segments[-1].succ - self.class.new segments.join(".") - end + @@bump[self] ||= begin + segments = self.segments + segments.pop while segments.any? { |s| String === s } + segments.pop if segments.size > 1 + + segments[-1] = segments[-1].succ + self.class.new segments.join(".") + end end ## @@ -306,13 +308,13 @@ class Gem::Version # Non-prerelease versions return themselves. def release - @release ||= if prerelease? - segments = self.segments - segments.pop while segments.any? { |s| String === s } - self.class.new segments.join('.') - else - self - end + @@release[self] ||= if prerelease? + segments = self.segments + segments.pop while segments.any? { |s| String === s } + self.class.new segments.join('.') + else + self + end end def segments # :nodoc: @@ -374,6 +376,12 @@ class Gem::Version end.reduce(&:concat) end + def freeze + prerelease? + canonical_segments + super + end + protected def _version -- cgit v1.2.3