summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <[email protected]>2025-01-02 20:29:46 +0100
committerHiroshi SHIBATA <[email protected]>2025-01-20 13:50:25 +0900
commit976cee57b126cd0876bf3a1f1a1d58266e488643 (patch)
tree74d413d1cd2601bfbc7a004b0ca5fbabd96ca1e3
parentb00315e95a7154d5b8c84c61c65fa21a3424aa06 (diff)
[rubygems/rubygems] Don't fallback to evaluating YAML gemspecs as Ruby code
https://github.com/rubygems/rubygems/commit/ca0a7ff8cd
-rw-r--r--lib/bundler.rb22
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 0480cac1a8..eea3b0cf17 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -547,15 +547,7 @@ module Bundler
def load_gemspec_uncached(file, validate = false)
path = Pathname.new(file)
contents = read_file(file)
- spec = if contents.start_with?("---") # YAML header
- eval_yaml_gemspec(path, contents)
- else
- # Eval the gemspec from its parent directory, because some gemspecs
- # depend on "./" relative paths.
- SharedHelpers.chdir(path.dirname.to_s) do
- eval_gemspec(path, contents)
- end
- end
+ spec = eval_gemspec(path, contents)
return unless spec
spec.loaded_from = path.expand_path.to_s
Bundler.rubygems.validate(spec) if validate
@@ -657,12 +649,18 @@ module Bundler
Kernel.require "psych"
Gem::Specification.from_yaml(contents)
- rescue ::Psych::SyntaxError, ArgumentError, Gem::EndOfYAMLException, Gem::Exception
- eval_gemspec(path, contents)
end
def eval_gemspec(path, contents)
- eval(contents, TOPLEVEL_BINDING.dup, path.expand_path.to_s)
+ if contents.start_with?("---") # YAML header
+ eval_yaml_gemspec(path, contents)
+ else
+ # Eval the gemspec from its parent directory, because some gemspecs
+ # depend on "./" relative paths.
+ SharedHelpers.chdir(path.dirname.to_s) do
+ eval(contents, TOPLEVEL_BINDING.dup, path.expand_path.to_s)
+ end
+ end
rescue ScriptError, StandardError => e
msg = "There was an error while loading `#{path.basename}`: #{e.message}"