keg: fix normalize_pod2man_outputs! for non-UTF-8 manpages

This commit is contained in:
Caleb Xu 2025-03-10 03:06:46 -04:00
parent 9c11f1b637
commit 7f28b979af
No known key found for this signature in database
GPG Key ID: 47E6040D07B8407D

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")