which: don't fail on malformed paths in PATH

This commit is contained in:
Baptiste Fontaine 2015-08-14 22:57:49 +02:00
parent 6606c7b53b
commit c631fc3013

View File

@ -244,7 +244,13 @@ end
def which(cmd, path = ENV["PATH"])
path.split(File::PATH_SEPARATOR).each do |p|
pcmd = File.expand_path(cmd, p)
begin
pcmd = File.expand_path(cmd, p)
rescue ArgumentError
# File.expand_path will raise an ArgumentError if the path is malformed.
# See https://github.com/Homebrew/homebrew/issues/32789
next
end
return Pathname.new(pcmd) if File.file?(pcmd) && File.executable?(pcmd)
end
nil