1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] fix dangling empty hooks

it turns out that running `bundle plugin uninstall some-plugin` would remove that plugin from the list of hooks, but if the list of hooks for an event was now empty, we would serialize the empty array into yaml as an empty single bullet item. which would then get unserialized as a plugin with the name empty string. which we would then try to load and explode. 😬

https://github.com/rubygems/rubygems/commit/545ebba9a5
This commit is contained in:
Andre Arko 2021-07-13 02:13:48 -07:00 committed by Hiroshi SHIBATA
parent a3d2200b2a
commit c5f78ade5a
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
2 changed files with 10 additions and 1 deletions

View file

@ -74,7 +74,10 @@ module Bundler
def unregister_plugin(name)
@commands.delete_if {|_, v| v == name }
@sources.delete_if {|_, v| v == name }
@hooks.each {|_, plugin_names| plugin_names.delete(name) }
@hooks.each do |hook, names|
names.delete(name)
@hooks.delete(hook) if names.empty?
end
@plugin_paths.delete(name)
@load_paths.delete(name)
save_index

View file

@ -98,6 +98,12 @@ RSpec.describe Bundler::Plugin::Index do
expect(index.hook_plugins("after-bar")).to eq([plugin_name])
end
it "is gone after unregistration" do
expect(index.index_file.read).to include("after-bar:\n - \"new-plugin\"\n")
index.unregister_plugin(plugin_name)
expect(index.index_file.read).to_not include("after-bar:\n - \n")
end
context "that are not registered" do
let(:file) { double("index-file") }