Skip to content

Commit

Permalink
Merge pull request #3854 from rubygems/brackets
Browse files Browse the repository at this point in the history
Fix some cases of running `bundler` on a path including brackets
  • Loading branch information
deivid-rodriguez committed Oct 1, 2020
2 parents 73ba6e1 + 7fe7e7b commit 9860c26
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bundler/lib/bundler/dsl.rb
Expand Up @@ -63,7 +63,7 @@ def gemspec(opts = nil)
development_group = opts[:development_group] || :development
expanded_path = gemfile_root.join(path)

gemspecs = Dir[File.join(expanded_path, "{,*}.gemspec")].map {|g| Bundler.load_gemspec(g) }.compact
gemspecs = Gem::Util.glob_files_in_dir("{,*}.gemspec", expanded_path).map {|g| Bundler.load_gemspec(g) }.compact
gemspecs.reject! {|s| s.name != name } if name
Index.sort_specs(gemspecs)
specs_by_name_and_version = gemspecs.group_by {|s| [s.name, s.version] }
Expand Down
4 changes: 2 additions & 2 deletions bundler/lib/bundler/gem_helper.rb
Expand Up @@ -32,7 +32,7 @@ def gemspec(&block)

def initialize(base = nil, name = nil)
@base = File.expand_path(base || SharedHelpers.pwd)
gemspecs = name ? [File.join(@base, "#{name}.gemspec")] : Dir[File.join(@base, "{,*}.gemspec")]
gemspecs = name ? [File.join(@base, "#{name}.gemspec")] : Gem::Util.glob_files_in_dir("{,*}.gemspec", @base)
raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1
@spec_path = gemspecs.first
@gemspec = Bundler.load_gemspec(@spec_path)
Expand Down Expand Up @@ -111,7 +111,7 @@ def rubygem_push(path)
end

def built_gem_path
Dir[File.join(base, "#{name}-*.gem")].sort_by {|f| File.mtime(f) }.last
Gem::Util.glob_files_in_dir("#{name}-*.gem", base).sort_by {|f| File.mtime(f) }.last
end

def git_push(remote = nil)
Expand Down
16 changes: 16 additions & 0 deletions bundler/lib/bundler/rubygems_ext.rb
Expand Up @@ -173,6 +173,22 @@ def hash
undef_method :eql? if method_defined? :eql?
alias_method :eql?, :==
end

require "rubygems/util"

Util.singleton_class.module_eval do
if Util.singleton_methods.include?(:glob_files_in_dir) # since 3.0.0.beta.2
remove_method :glob_files_in_dir
end

def glob_files_in_dir(glob, base_path)
if RUBY_VERSION >= "2.5"
Dir.glob(glob, :base => base_path).map! {|f| File.expand_path(f, base_path) }
else
Dir.glob(File.join(base_path.to_s.gsub(/[\[\]]/, '\\\\\\&'), glob)).map! {|f| File.expand_path(f) }
end
end
end
end

module Gem
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/source/path.rb
Expand Up @@ -171,7 +171,7 @@ def load_spec_files

if File.directory?(expanded_path)
# We sort depth-first since `<<` will override the earlier-found specs
Dir["#{expanded_path}/#{@glob}"].sort_by {|p| -p.split(File::SEPARATOR).size }.each do |file|
Gem::Util.glob_files_in_dir(@glob, expanded_path).sort_by {|p| -p.split(File::SEPARATOR).size }.each do |file|
next unless spec = load_gemspec(file)
spec.source = self

Expand Down
18 changes: 17 additions & 1 deletion bundler/spec/commands/install_spec.rb
Expand Up @@ -511,7 +511,7 @@
end

describe "when Bundler root contains regex chars" do
it "doesn't blow up" do
it "doesn't blow up when using the `gem` DSL" do
root_dir = tmp("foo[]bar")

FileUtils.mkdir_p(root_dir)
Expand All @@ -526,6 +526,22 @@

bundle :install, :dir => root_dir
end

it "doesn't blow up when using the `gemspec` DSL" do
root_dir = tmp("foo[]bar")

FileUtils.mkdir_p(root_dir)

build_lib "foo", :path => root_dir
gemfile = <<-G
gemspec
G
File.open("#{root_dir}/Gemfile", "w") do |file|
file.puts gemfile
end

bundle :install, :dir => root_dir
end
end

describe "when requesting a quiet install via --quiet" do
Expand Down
4 changes: 2 additions & 2 deletions bundler/spec/realworld/fixtures/warbler/Gemfile.lock
Expand Up @@ -6,7 +6,7 @@ PATH
GEM
remote: https://rubygems.org/
specs:
jruby-jars (9.2.9.0)
jruby-jars (9.2.11.1)
jruby-rack (1.1.21)
rake (13.0.1)
rubyzip (1.3.0)
Expand All @@ -26,4 +26,4 @@ DEPENDENCIES
warbler (~> 2.0)

BUNDLED WITH
2.2.0.rc.1
2.2.0.rc.2
12 changes: 12 additions & 0 deletions bundler/spec/runtime/gem_tasks_spec.rb
Expand Up @@ -67,6 +67,18 @@
end
end

context "rake build when path has brackets", :ruby_repo do
before do
bracketed_bundled_app = tmp.join("bundled[app")
FileUtils.cp_r bundled_app, bracketed_bundled_app
bundle "exec rake build", :dir => bracketed_bundled_app
end

it "still runs successfully" do
expect(err).to be_empty
end
end

context "bundle path configured locally" do
before do
bundle "config set path vendor/bundle"
Expand Down

0 comments on commit 9860c26

Please sign in to comment.