Skip to content

Commit

Permalink
Fix Bundler.which not working on Windows
Browse files Browse the repository at this point in the history
It was ignoring executable extensions, which is the only hint
`File.executable?` uses on Windows to figure out executability.
  • Loading branch information
deivid-rodriguez committed May 24, 2021
1 parent 4ff4050 commit 376c5c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions bundler/lib/bundler.rb
Expand Up @@ -512,14 +512,18 @@ def mkdir_p(path, options = {})
end

def which(executable)
exts = (RbConfig::CONFIG["EXECUTABLE_EXTS"]&.split || []) | [RbConfig::CONFIG["EXEEXT"]]

if File.file?(executable) && File.executable?(executable)
executable
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)
exts.find do |ext|
executable_path = File.expand_path(executable + ext, path)
return executable_path if File.file?(executable_path) && File.executable?(executable_path)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion bundler/spec/bundler/bundler_spec.rb
Expand Up @@ -159,7 +159,7 @@
context "when the executable in inside a quoted path" do
let(:expected) do
if Gem.win_platform?
"C:/e/executable"
"C:/e/executable.cmd"
else
"/e/executable"
end
Expand Down

0 comments on commit 376c5c2

Please sign in to comment.