diff options
author | Carsten Wirth <carsten.wirth@homeday.de> | 2019-11-26 15:48:55 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2020-06-05 07:32:42 +0900 |
commit | 0ae5cd55e5c764c8fb14c63eb663cdbff355434e (patch) | |
tree | 0480b0e8d96762ec1cc8f307203acbafaf047e0c /lib | |
parent | c91915c1838e2492a433b00179f0cef5d72abde0 (diff) |
[rubygems/rubygems] Remove multiline gem specifications correctly
https://github.com/rubygems/rubygems/commit/8dca0ad56e
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3184
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/injector.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index 767c5ff2fe..6694642246 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -180,8 +180,19 @@ module Bundler def remove_gems_from_gemfile(gems, gemfile_path) patterns = /gem\s+(['"])#{Regexp.union(gems)}\1|gem\s*\((['"])#{Regexp.union(gems)}\2\)/ - # remove lines which match the regex - new_gemfile = IO.readlines(gemfile_path).reject {|line| line.match(patterns) } + new_gemfile = [] + multiline_removal = false + IO.readlines(gemfile_path).each do |line| + if line.match(patterns) + multiline_removal = line.rstrip.end_with?(",") + # skip lines which match the regex + next + end + + # skip followup lines until line does not end with ',' + new_gemfile << line unless multiline_removal + multiline_removal = line.rstrip.end_with?(",") if multiline_removal + end # remove line \n and append them with other strings new_gemfile.each_with_index do |_line, index| |