XUnit Formatter: Handle UTF-8 decode errors on invalid XML

Strings which contain garbage data can trigger an exception in the XUnit
plugin at the UTF-8 decode step because the decode is strict. Use a lax
mode to avoid an exception.

See: https://ci.swift.org/job/oss-lldb-incremental-osx/780
llvm-svn: 323817
This commit is contained in:
Vedant Kumar 2018-01-30 21:16:42 +00:00
parent b7d1729787
commit e2fbd7035d
1 changed files with 3 additions and 1 deletions

View File

@ -84,7 +84,9 @@ class XunitFormatter(ResultsFormatter):
"""
# Get the content into unicode
if isinstance(str_or_unicode, str):
unicode_content = str_or_unicode.decode('utf-8')
# If we hit decoding errors due to data corruption, replace the
# invalid characters with U+FFFD REPLACEMENT CHARACTER.
unicode_content = str_or_unicode.decode('utf-8', 'replace')
else:
unicode_content = str_or_unicode
return self.invalid_xml_re.sub(