Check if `Kernel#untaint` is defined instead of version comparison

Probably `RUBY_VERSION` seems overwritten somewhere in the tests.
This commit is contained in:
Nobuyoshi Nakada 2021-12-27 08:56:00 +09:00 коммит произвёл GitHub
Родитель 1f877fa238
Коммит 9736cb890b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 8 добавлений и 8 удалений

Просмотреть файл

@ -46,7 +46,7 @@ module Bundler
@gemfile = expanded_gemfile_path
@gemfiles << expanded_gemfile_path
contents ||= Bundler.read_file(@gemfile.to_s)
instance_eval(contents.dup.tap{|x| x.untaint if RUBY_VERSION < "2.7" }, gemfile.to_s, 1)
instance_eval(contents.dup.tap{|x| x.untaint if Kernel.method_defined?(:untaint) }, gemfile.to_s, 1)
rescue Exception => e # rubocop:disable Lint/RescueException
message = "There was an error " \
"#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \

Просмотреть файл

@ -29,7 +29,7 @@ module Gem
# gems at that time, this method could be called inside another require,
# thus raising with that constant being undefined. Better to check a method
if source.respond_to?(:path) || (source.respond_to?(:bundler_plugin_api_source?) && source.bundler_plugin_api_source?)
Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.tap{|x| x.untaint if RUBY_VERSION < "2.7" }
Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.tap{|x| x.untaint if Kernel.method_defined?(:untaint) }
else
rg_full_gem_path
end

Просмотреть файл

@ -13,13 +13,13 @@ module Bundler
def root
gemfile = find_gemfile
raise GemfileNotFound, "Could not locate Gemfile" unless gemfile
Pathname.new(gemfile).tap{|x| x.untaint if RUBY_VERSION < "2.7" }.expand_path.parent
Pathname.new(gemfile).tap{|x| x.untaint if Kernel.method_defined?(:untaint) }.expand_path.parent
end
def default_gemfile
gemfile = find_gemfile
raise GemfileNotFound, "Could not locate Gemfile" unless gemfile
Pathname.new(gemfile).tap{|x| x.untaint if RUBY_VERSION < "2.7" }.expand_path
Pathname.new(gemfile).tap{|x| x.untaint if Kernel.method_defined?(:untaint) }.expand_path
end
def default_lockfile
@ -28,7 +28,7 @@ module Bundler
case gemfile.basename.to_s
when "gems.rb" then Pathname.new(gemfile.sub(/.rb$/, ".locked"))
else Pathname.new("#{gemfile}.lock")
end.tap{|x| x.untaint if RUBY_VERSION < "2.7" }
end.tap{|x| x.untaint if Kernel.method_defined?(:untaint) }
end
def default_bundle_dir
@ -100,7 +100,7 @@ module Bundler
#
# @see {Bundler::PermissionError}
def filesystem_access(path, action = :write, &block)
yield(path.dup.tap{|x| x.untaint if RUBY_VERSION < "2.7" })
yield(path.dup.tap{|x| x.untaint if Kernel.method_defined?(:untaint) })
rescue Errno::EACCES
raise PermissionError.new(path, action)
rescue Errno::EAGAIN
@ -236,7 +236,7 @@ module Bundler
def search_up(*names)
previous = nil
current = File.expand_path(SharedHelpers.pwd).tap{|x| x.untaint if RUBY_VERSION < "2.7" }
current = File.expand_path(SharedHelpers.pwd).tap{|x| x.untaint if Kernel.method_defined?(:untaint) }
until !File.directory?(current) || current == previous
if ENV["BUNDLER_SPEC_RUN"]

Просмотреть файл

@ -336,7 +336,7 @@ module Bundler
def load_gemspec(file)
stub = Gem::StubSpecification.gemspec_stub(file, install_path.parent, install_path.parent)
stub.full_gem_path = Pathname.new(file).dirname.expand_path(root).to_s.tap{|x| x.untaint if RUBY_VERSION < "2.7" }
stub.full_gem_path = Pathname.new(file).dirname.expand_path(root).to_s.tap{|x| x.untaint if Kernel.method_defined?(:untaint) }
StubSpecification.from_stub(stub)
end