From d43765c3a9d006599895538be12b5b45c1873085 Mon Sep 17 00:00:00 2001 From: Martin Emde Date: Fri, 1 Sep 2023 15:47:58 -0700 Subject: [PATCH] [rubygems/rubygems] Unify LockfileParser loading of SPECS section Ensure unrecognized SPECS types are ignored https://github.com/rubygems/rubygems/commit/5b33e91075 --- lib/bundler/lockfile_parser.rb | 18 +++--------------- lib/bundler/plugin.rb | 2 +- lib/bundler/source/rubygems.rb | 1 + spec/bundler/bundler/plugin_spec.rb | 4 ++-- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index 7360a36752..0127634428 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -110,21 +110,9 @@ module Bundler def parse_source(line) case line when SPECS - case @type - when PATH - @current_source = TYPES[@type].from_lock(@opts) - @sources << @current_source - when GIT - @current_source = TYPES[@type].from_lock(@opts) - @sources << @current_source - when GEM - @opts["remotes"] = Array(@opts.delete("remote")).reverse - @current_source = TYPES[@type].from_lock(@opts) - @sources << @current_source - when PLUGIN - @current_source = Plugin.source_from_lock(@opts) - @sources << @current_source - end + return unless TYPES.key?(@type) + @current_source = TYPES[@type].from_lock(@opts) + @sources << @current_source when OPTIONS value = $2 value = true if value == "true" diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index f3caff8963..e6aaa6b464 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -197,7 +197,7 @@ module Bundler # @param [Hash] The options that are present in the lock file # @return [API::Source] the instance of the class that handles the source # type passed in locked_opts - def source_from_lock(locked_opts) + def from_lock(locked_opts) src = source(locked_opts["type"]) src.new(locked_opts.merge("uri" => locked_opts["remote"])) diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 44102c47c8..3d4d2eeec1 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -88,6 +88,7 @@ module Bundler end def self.from_lock(options) + options["remotes"] = Array(options.delete("remote")).reverse new(options) end diff --git a/spec/bundler/bundler/plugin_spec.rb b/spec/bundler/bundler/plugin_spec.rb index d28479cf31..1731a2085e 100644 --- a/spec/bundler/bundler/plugin_spec.rb +++ b/spec/bundler/bundler/plugin_spec.rb @@ -225,7 +225,7 @@ RSpec.describe Bundler::Plugin do end end - describe "#source_from_lock" do + describe "#from_lock" do it "returns instance of registered class initialized with locked opts" do opts = { "type" => "l_source", "remote" => "xyz", "other" => "random" } allow(index).to receive(:source_plugin).with("l_source") { "plugin_name" } @@ -236,7 +236,7 @@ RSpec.describe Bundler::Plugin do expect(SClass).to receive(:new). with(hash_including("type" => "l_source", "uri" => "xyz", "other" => "random")) { s_instance } - expect(subject.source_from_lock(opts)).to be(s_instance) + expect(subject.from_lock(opts)).to be(s_instance) end end