summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-08-30 15:13:20 +0000
committerThe Bundler Bot <bot@bundler.io>2017-08-30 15:13:20 +0000
commit570012724216e8a4f8cd2ffe9eb8acdfc94be133 (patch)
tree8ad81828ebc8185d971f66f9edb94f4c917ea829
parent46b4b2f23c3d50314bed694fc634380798ba0721 (diff)
parentbb817c6f0344fcee2c7310eaca250abee4819c2b (diff)
downloadbundler-570012724216e8a4f8cd2ffe9eb8acdfc94be133.tar.gz
Auto merge of #5978 - torcido:master, r=segiddins
Support bundle_path used by war files generated with jruby's warbler ### What was the end-user problem that led to this PR? Issue #5975. The problem was that recent code to detect a bad bundle_path by looking for the PATH_SEPARATOR character broke when running from a war file generated by jruby's warbler. ### What was your diagnosis of the problem? My diagnosis was that the path separator used was not appropriate in this circumstance. ### What is your fix for the problem, implemented in this PR? My fix implements the suggestion from @segiddins to use the same path splitting logic used by RubyGems under jruby to determine if the bad path is present. ### Why did you choose this fix out of the possible options? I chose this fix because it provides a way to detect the original problem that is consistent with the handling within RubyGems.
-rw-r--r--lib/bundler/rubygems_integration.rb8
-rw-r--r--lib/bundler/shared_helpers.rb7
-rw-r--r--spec/bundler/shared_helpers_spec.rb41
3 files changed, 49 insertions, 7 deletions
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index 6f8a7608b0..1185625e03 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -208,6 +208,10 @@ module Bundler
Gem.bin_path(gem, bin, ver)
end
+ def path_separator
+ File::PATH_SEPARATOR
+ end
+
def preserve_paths
# this is a no-op outside of RubyGems 1.8
yield
@@ -788,6 +792,10 @@ module Bundler
def install_with_build_args(args)
yield
end
+
+ def path_separator
+ Gem.path_separator
+ end
end
# RubyGems 2.1.0
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index bef9cc6139..a18966b324 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -221,12 +221,13 @@ module Bundler
private
def validate_bundle_path
- return unless Bundler.bundle_path.to_s.include?(File::PATH_SEPARATOR)
- message = "Your bundle path contains a '#{File::PATH_SEPARATOR}', " \
+ path_separator = Bundler.rubygems.path_separator
+ return unless Bundler.bundle_path.to_s.split(path_separator).size > 1
+ message = "Your bundle path contains text matching #{path_separator.inspect}, " \
"which is the path separator for your system. Bundler cannot " \
"function correctly when the Bundle path contains the " \
"system's PATH separator. Please change your " \
- "bundle path to not include '#{File::PATH_SEPARATOR}'." \
+ "bundle path to not match #{path_separator.inspect}." \
"\nYour current bundle path is '#{Bundler.bundle_path}'."
raise Bundler::PathError, message
end
diff --git a/spec/bundler/shared_helpers_spec.rb b/spec/bundler/shared_helpers_spec.rb
index 66aaf2cf82..b8f099d5ba 100644
--- a/spec/bundler/shared_helpers_spec.rb
+++ b/spec/bundler/shared_helpers_spec.rb
@@ -261,20 +261,53 @@ RSpec.describe Bundler::SharedHelpers do
subject.set_bundle_environment
end
- it "exits if bundle path contains the path separator" do
- stub_const("File::PATH_SEPARATOR", ":".freeze)
+ it "exits if bundle path contains the unix-like path separator" do
+ if Gem.respond_to?(:path_separator)
+ allow(Gem).to receive(:path_separator).and_return(":")
+ else
+ stub_const("File::PATH_SEPARATOR", ":".freeze)
+ end
allow(Bundler).to receive(:bundle_path) { Pathname.new("so:me/dir/bin") }
expect { subject.send(:validate_bundle_path) }.to raise_error(
Bundler::PathError,
- "Your bundle path contains a ':', which is the " \
+ "Your bundle path contains text matching \":\", which is the " \
"path separator for your system. Bundler cannot " \
"function correctly when the Bundle path contains the " \
"system's PATH separator. Please change your " \
- "bundle path to not include ':'.\nYour current bundle " \
+ "bundle path to not match \":\".\nYour current bundle " \
"path is '#{Bundler.bundle_path}'."
)
end
+ context "with a jruby path_separator regex", :ruby => "1.9" do
+ # In versions of jruby that supported ruby 1.8, the path separator was the standard File::PATH_SEPARATOR
+ let(:regex) { Regexp.new("(?<!jar:file|jar|file|classpath|uri:classloader|uri|http|https):") }
+ it "does not exit if bundle path is the standard uri path" do
+ allow(Bundler.rubygems).to receive(:path_separator).and_return(regex)
+ allow(Bundler).to receive(:bundle_path) { Pathname.new("uri:classloader:/WEB-INF/gems") }
+ expect { subject.send(:validate_bundle_path) }.not_to raise_error
+ end
+
+ it "exits if bundle path contains another directory" do
+ allow(Bundler.rubygems).to receive(:path_separator).and_return(regex)
+ allow(Bundler).to receive(:bundle_path) {
+ Pathname.new("uri:classloader:/WEB-INF/gems:other/dir")
+ }
+
+ expect { subject.send(:validate_bundle_path) }.to raise_error(
+ Bundler::PathError,
+ "Your bundle path contains text matching " \
+ "/(?<!jar:file|jar|file|classpath|uri:classloader|uri|http|https):/, which is the " \
+ "path separator for your system. Bundler cannot " \
+ "function correctly when the Bundle path contains the " \
+ "system's PATH separator. Please change your " \
+ "bundle path to not match " \
+ "/(?<!jar:file|jar|file|classpath|uri:classloader|uri|http|https):/." \
+ "\nYour current bundle path is '#{Bundler.bundle_path}'."
+ )
+ end
+ end
+
context "ENV['PATH'] does not exist" do
before { ENV.delete("PATH") }