diff options
-rw-r--r-- | lib/bundler/rubygems_integration.rb | 8 | ||||
-rw-r--r-- | lib/bundler/shared_helpers.rb | 7 | ||||
-rw-r--r-- | spec/bundler/shared_helpers_spec.rb | 41 |
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") } |