Handle non-ASCII output encoded as ASCII

Some tool involved in `brew install node` is emitting UTF-8 even though
LANG and LC_ALL are unset. Since the external encoding is US-ASCII, we
need to guard against bad data here.
This commit is contained in:
Jack Nagel 2014-06-14 00:05:20 -05:00
parent 4b07dbbf78
commit 03488424cb

View File

@ -522,7 +522,11 @@ if ARGV.include? "--junit"
failure = testcase.add_element 'failure' if step.failed? failure = testcase.add_element 'failure' if step.failed?
if step.has_output? if step.has_output?
# Remove invalid XML CData characters from step output. # Remove invalid XML CData characters from step output.
output = REXML::CData.new step.output.delete("\000\a\b\e\f") output = step.output
if output.respond_to?(:force_encoding) && !output.valid_encoding?
output.force_encoding(Encoding::UTF_8)
end
output = REXML::CData.new output.delete("\000\a\b\e\f")
if step.passed? if step.passed?
system_out = testcase.add_element 'system-out' system_out = testcase.add_element 'system-out'
system_out.text = output system_out.text = output