From 7f28b979af142d778281f00c59c19364a7343d74 Mon Sep 17 00:00:00 2001 From: Caleb Xu Date: Mon, 10 Mar 2025 03:06:46 -0400 Subject: [PATCH] keg: fix normalize_pod2man_outputs! for non-UTF-8 manpages --- Library/Homebrew/keg.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index c7035fcf8c..4e4218fbd5 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -566,6 +566,15 @@ class Keg next unless manpage.file? content = manpage.read + unless content.valid_encoding? + # Occasionally, a manpage might not be encoded as UTF-8. ISO-8859-1 is a + # common alternative that's worth trying in this case. + content = File.read(manpage, encoding: "ISO-8859-1") + + # If the encoding is still invalid, we can't do anything about it. + next unless content.valid_encoding? + end + content = content.gsub(generated_regex, "") content = content.lines.map do |line| next line unless line.start_with?(".TH")