Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Handle quotes in PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Feb 28, 2016
1 parent a69ec8f commit fdd130e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ 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)
path.split(File::PATH_SEPARATOR).find do |path|

This comment has been minimized.

Copy link
@allenzhao

allenzhao Feb 29, 2016

Contributor

Seems this line caused build problem.. maybe change the first path to paths?

path = path[1..-2] if path[0] == '"' && path[-1] == '"'
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

Expand Down
37 changes: 37 additions & 0 deletions spec/bundler/bundler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,41 @@
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

0 comments on commit fdd130e

Please sign in to comment.