Merge pull request #19449 from Homebrew/non-utf8-manpages

keg: fix normalize_pod2man_outputs! for non-UTF-8 manpages
This commit is contained in:
Mike McQuaid 2025-03-10 08:55:47 +00:00 committed by GitHub
commit f5a53241a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -566,6 +566,15 @@ class Keg
next unless manpage.file? next unless manpage.file?
content = manpage.read 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.gsub(generated_regex, "")
content = content.lines.map do |line| content = content.lines.map do |line|
next line unless line.start_with?(".TH") next line unless line.start_with?(".TH")