Skip to content

Commit

Permalink
Fix using the gemspec DSL on a path with brackets in its name
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Jul 24, 2020
1 parent 9f97e05 commit 4270b54
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bundler/lib/bundler/dsl.rb
Expand Up @@ -62,8 +62,8 @@ def gemspec(opts = nil)
name = opts[:name]
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
escaped_expanded_path = Bundler::Thor::Util.escape_globs(expanded_path)
gemspecs = Dir[File.join(escaped_expanded_path, "{,*}.gemspec")].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
3 changes: 2 additions & 1 deletion bundler/lib/bundler/source/path.rb
Expand Up @@ -170,8 +170,9 @@ def load_spec_files
index = Index.new

if File.directory?(expanded_path)
escaped_expanded_path = Bundler::Thor::Util.escape_globs(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|
Dir["#{escaped_expanded_path}/#{@glob}"].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 @@ -501,7 +501,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 @@ -516,6 +516,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

0 comments on commit 4270b54

Please sign in to comment.