Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Only untaint strings on Ruby <2.7
Browse files Browse the repository at this point in the history
Ruby 2.7 deprecates taint and it no longer has an effect.
This attempts to leave the behavior the same on older
Ruby versions, but avoid the use of untaint on Ruby 2.7+.

See https://bugs.ruby-lang.org/issues/16131 for details.
  • Loading branch information
jeremyevans committed Oct 18, 2019
1 parent c9d1635 commit 8b1b7c1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/bundler/dsl.rb
Expand Up @@ -44,7 +44,7 @@ def eval_gemfile(gemfile, contents = nil)
@gemfile = expanded_gemfile_path
@gemfiles << expanded_gemfile_path
contents ||= Bundler.read_file(@gemfile.to_s)
instance_eval(contents.dup.untaint, gemfile.to_s, 1)
instance_eval(contents.dup.tap{|x| x.untaint if RUBY_VERSION < "2.7" }, gemfile.to_s, 1)
rescue Exception => e # rubocop:disable Lint/RescueException
message = "There was an error " \
"#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/rubygems_ext.rb
Expand Up @@ -29,7 +29,7 @@ def full_gem_path
# 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.untaint
Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.tap{|x| x.untaint if RUBY_VERSION < "2.7" }
else
rg_full_gem_path
end
Expand Down
10 changes: 5 additions & 5 deletions lib/bundler/shared_helpers.rb
Expand Up @@ -13,13 +13,13 @@ module SharedHelpers
def root
gemfile = find_gemfile
raise GemfileNotFound, "Could not locate Gemfile" unless gemfile
Pathname.new(gemfile).untaint.expand_path.parent
Pathname.new(gemfile).tap{|x| x.untaint if RUBY_VERSION < "2.7" }.expand_path.parent
end

def default_gemfile
gemfile = find_gemfile
raise GemfileNotFound, "Could not locate Gemfile" unless gemfile
Pathname.new(gemfile).untaint.expand_path
Pathname.new(gemfile).tap{|x| x.untaint if RUBY_VERSION < "2.7" }.expand_path
end

def default_lockfile
Expand All @@ -28,7 +28,7 @@ def default_lockfile
case gemfile.basename.to_s
when "gems.rb" then Pathname.new(gemfile.sub(/.rb$/, ".locked"))
else Pathname.new("#{gemfile}.lock")
end.untaint
end.tap{|x| x.untaint if RUBY_VERSION < "2.7" }
end

def default_bundle_dir
Expand Down Expand Up @@ -100,7 +100,7 @@ def set_bundle_environment
#
# @see {Bundler::PermissionError}
def filesystem_access(path, action = :write, &block)
yield(path.dup.untaint)
yield(path.dup.tap{|x| x.untaint if RUBY_VERSION < "2.7" })
rescue Errno::EACCES
raise PermissionError.new(path, action)
rescue Errno::EAGAIN
Expand Down Expand Up @@ -268,7 +268,7 @@ def find_directory(*names)

def search_up(*names)
previous = nil
current = File.expand_path(SharedHelpers.pwd).untaint
current = File.expand_path(SharedHelpers.pwd).tap{|x| x.untaint if RUBY_VERSION < "2.7" }

until !File.directory?(current) || current == previous
if ENV["BUNDLE_SPEC_RUN"]
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/source/git.rb
Expand Up @@ -316,7 +316,7 @@ def validate_spec(_spec); end

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.untaint
stub.full_gem_path = Pathname.new(file).dirname.expand_path(root).to_s.tap{|x| x.untaint if RUBY_VERSION < "2.7" }
StubSpecification.from_stub(stub)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/vendor/fileutils/lib/fileutils.rb
Expand Up @@ -1300,7 +1300,7 @@ def entries
.reject {|n| n == '.' or n == '..' }
end

files.map {|n| Entry_.new(prefix(), join(rel(), n.untaint)) }
files.map {|n| Entry_.new(prefix(), join(rel(), n.tap{|x| x.untaint if RUBY_VERSION < "2.7" })) }
end

def stat
Expand Down

0 comments on commit 8b1b7c1

Please sign in to comment.