Skip to content
Snippets Groups Projects
Commit 7f230dfa authored by Jack Nagel's avatar Jack Nagel
Browse files

Suppress encoding errors in test-bot log files

parent 91ccd843
No related branches found
No related tags found
No related merge requests found
......@@ -129,7 +129,7 @@ module Homebrew
puts_result
if File.exist?(log)
@output = File.read(log)
@output = fix_encoding File.read(log)
if has_output? and (failed? or @puts_output_on_success)
puts @output
end
......@@ -138,6 +138,22 @@ module Homebrew
exit 1 if ARGV.include?("--fail-fast") && @status == :failed
end
private
if String.method_defined?(:force_encoding)
def fix_encoding(str)
return str if str.valid_encoding?
# Assume we are starting from a "mostly" UTF-8 string
str.force_encoding(Encoding::UTF_8)
str.encode!(Encoding::UTF_16, :invalid => :replace, :undef => :replace)
str.encode!(Encoding::UTF_8)
end
else
def fix_encoding(str)
str
end
end
end
class Test
......@@ -630,12 +646,11 @@ module Homebrew
testcase.attributes['time'] = step.time
failure = testcase.add_element 'failure' if step.failed?
if step.has_output?
# Remove invalid XML CData characters from step output.
output = step.output
if output.respond_to?(:force_encoding) && !output.valid_encoding?
output.force_encoding(Encoding::UTF_8)
end
# Remove invalid XML CData characters from step output.
output = output.delete("\000\a\b\e\f")
if output.bytesize > BYTES_IN_1_MEGABYTE
output = "truncated output to 1MB:\n" \
+ output.slice(-BYTES_IN_1_MEGABYTE, BYTES_IN_1_MEGABYTE)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment