aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorTim D. Smith2016-10-16 09:47:02 -0700
committerGitHub2016-10-16 09:47:02 -0700
commitde880f1e870d91dd838228de2987f9bd6d194aef (patch)
treef89129bd9a9f5b86e5083a72f9f5b26b5b97d78b /Library
parent87fad259a026dba8333934b7d92a244c59eaba50 (diff)
parent22a64aa6c630ad73c3830cf3bbbf129bfbc4d19c (diff)
downloadbrew-de880f1e870d91dd838228de2987f9bd6d194aef.tar.bz2
Merge pull request #1298 from tdsmith/no-no-bad-unicode
Don't choke on invalid UTF-8 in `file` output
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/keg_relocate.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/Library/Homebrew/keg_relocate.rb b/Library/Homebrew/keg_relocate.rb
index ab037da98..17911b90b 100644
--- a/Library/Homebrew/keg_relocate.rb
+++ b/Library/Homebrew/keg_relocate.rb
@@ -84,9 +84,16 @@ class Keg
}
output, _status = Open3.capture2("/usr/bin/xargs -0 /usr/bin/file --no-dereference --print0",
stdin_data: files.to_a.join("\0"))
+ # `file` output sometimes contains data from the file, which may include
+ # invalid UTF-8 entities, so tell Ruby this is just a bytestring
+ output.force_encoding(Encoding::ASCII_8BIT)
output.each_line do |line|
- path, info = line.split("\0")
- next unless info.to_s.include?("text")
+ path, info = line.split("\0", 2)
+ # `file` sometimes prints more than one line of output per file;
+ # subsequent lines do not contain a null-byte separator, so `info`
+ # will be `nil` for those lines
+ next unless info
+ next unless info.include?("text")
path = Pathname.new(path)
next unless files.include?(path)
text_files << path