From c631fc30131bc429d0da60053c5169376a507aae Mon Sep 17 00:00:00 2001 From: Baptiste Fontaine Date: Fri, 14 Aug 2015 22:57:49 +0200 Subject: [PATCH] which: don't fail on malformed paths in PATH --- Library/Homebrew/utils.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index a6c47b27a8..1390db14e0 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -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