summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-03-01 13:18:04 +0900
committerHomu <homu@barosl.com>2016-03-01 13:18:04 +0900
commit5e2e2ff089af4875c54b27cfb5d4286471dff125 (patch)
tree8496680587cc7456bf7c5e324c6e740c27b537d6
parent72147e8f1b2f7f1dc4c4ac18a58ceb8b97e5c49c (diff)
parentbd0f564a7369aa9e81dcc8eaeff99fa717e13d37 (diff)
downloadbundler-5e2e2ff089af4875c54b27cfb5d4286471dff125.tar.gz
Auto merge of #4326 - bundler:seg-path-quotes, r=segiddins
Handle quotes in PATH Fixes #4323 and adds tests
-rw-r--r--lib/bundler.rb11
-rw-r--r--spec/bundler/bundler_spec.rb37
-rw-r--r--spec/realworld/edgecases_spec.rb2
3 files changed, 44 insertions, 6 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 2958e64cee..dcb151b058 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -303,12 +303,13 @@ module Bundler
def which(executable)
if File.file?(executable) && File.executable?(executable)
executable
- elsif path = ENV["PATH"]
- executable_path = path.split(File::PATH_SEPARATOR).find do |p|
- abs_path = File.join(p, executable)
- File.file?(abs_path) && File.executable?(abs_path)
+ elsif paths = ENV["PATH"]
+ quote = '"'.freeze
+ paths.split(File::PATH_SEPARATOR).find do |path|
+ path = path[1..-2] if path.start_with?(quote) && path.end_with?(quote)
+ executable_path = File.expand_path(executable, path)
+ return executable_path if File.file?(executable_path) && File.executable?(executable_path)
end
- executable_path && File.expand_path(executable, executable_path)
end
end
diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb
index 84d2922f37..2ad3704db0 100644
--- a/spec/bundler/bundler_spec.rb
+++ b/spec/bundler/bundler_spec.rb
@@ -103,4 +103,41 @@ describe Bundler do
end
end
end
+
+ describe "#which" do
+ let(:executable) { "executable" }
+ let(:path) { %w(/a /b c ../d "/e") }
+ let(:expected) { "executable" }
+
+ before do
+ ENV["PATH"] = path.join(File::PATH_SEPARATOR)
+
+ allow(File).to receive(:file?).and_return(false)
+ allow(File).to receive(:executable?).and_return(false)
+ if expected
+ expect(File).to receive(:file?).with(expected).and_return(true)
+ expect(File).to receive(:executable?).with(expected).and_return(true)
+ end
+ end
+
+ subject { described_class.which(executable) }
+
+ shared_examples_for "it returns the correct executable" do
+ it "returns the expected file" do
+ expect(subject).to eq(expected)
+ end
+ end
+
+ it_behaves_like "it returns the correct executable"
+
+ context "when the executable in inside a quoted path" do
+ let(:expected) { "/e/executable" }
+ it_behaves_like "it returns the correct executable"
+ end
+
+ context "when the executable is not found" do
+ let(:expected) { nil }
+ it_behaves_like "it returns the correct executable"
+ end
+ end
end
diff --git a/spec/realworld/edgecases_spec.rb b/spec/realworld/edgecases_spec.rb
index 8295669d19..2f0ba9866a 100644
--- a/spec/realworld/edgecases_spec.rb
+++ b/spec/realworld/edgecases_spec.rb
@@ -49,7 +49,7 @@ describe "real world edgecases", :realworld => true, :sometimes => true do
gem 'rack-cache', '1.2.0' # last version that works on Ruby 1.9
G
bundle :lock
- expect(lockfile).to include("rails (3.2.22.1)")
+ expect(lockfile).to include("rails (3.2.22.2)")
expect(lockfile).to include("capybara (2.2.1)")
end