From 890c83e6078f8796628afdb101548a4ed1961bb0 Mon Sep 17 00:00:00 2001 From: Jerome Dalbert Date: Wed, 20 Nov 2024 17:43:22 -0800 Subject: [PATCH] [rubygems/rubygems] Fix `bundle remove` sometimes not removing gems https://github.com/rubygems/rubygems/commit/e7f5f067e8 --- lib/bundler/injector.rb | 2 +- spec/bundler/commands/remove_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index c7e93c9ee0..182b736c56 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -184,7 +184,7 @@ module Bundler # @param [Array] gems Array of names of gems to be removed. # @param [Pathname] gemfile_path The Gemfile from which to remove dependencies. def remove_gems_from_gemfile(gems, gemfile_path) - patterns = /gem\s+(['"])#{Regexp.union(gems)}\1|gem\s*\((['"])#{Regexp.union(gems)}\2\)/ + patterns = /gem\s+(['"])#{Regexp.union(gems)}\1|gem\s*\((['"])#{Regexp.union(gems)}\2.*\)/ new_gemfile = [] multiline_removal = false File.readlines(gemfile_path).each do |line| diff --git a/spec/bundler/commands/remove_spec.rb b/spec/bundler/commands/remove_spec.rb index 7ac2ea9b26..84505169ca 100644 --- a/spec/bundler/commands/remove_spec.rb +++ b/spec/bundler/commands/remove_spec.rb @@ -729,4 +729,23 @@ RSpec.describe "bundle remove" do end end end + + context "when gem definition has parentheses" do + it "removes the gem" do + gemfile <<-G + source "https://gem.repo1" + + gem("myrack") + gem("myrack", ">= 0") + gem("myrack", require: false) + G + + bundle "remove myrack" + + expect(out).to include("myrack was removed.") + expect(gemfile).to eq <<~G + source "https://gem.repo1" + G + end + end end