[rubygems/rubygems] Unify LockfileParser loading of SPECS section

Ensure unrecognized SPECS types are ignored

https://github.com/rubygems/rubygems/commit/5b33e91075
This commit is contained in:
Martin Emde 2023-09-01 15:47:58 -07:00 коммит произвёл git
Родитель 0ae7f2d1ac
Коммит d43765c3a9
4 изменённых файлов: 7 добавлений и 18 удалений

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

@ -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"

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

@ -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"]))

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

@ -88,6 +88,7 @@ module Bundler
end
def self.from_lock(options)
options["remotes"] = Array(options.delete("remote")).reverse
new(options)
end

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

@ -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