Skip to content

Commit

Permalink
Merge pull request #1930 from rmmh/gubernator-update
Browse files Browse the repository at this point in the history
Make Gubernator handle corrupt JUnit files better.
  • Loading branch information
Ryan Hitchman committed Feb 18, 2017
2 parents e6565b9 + b14d264 commit 9f9e7af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
10 changes: 9 additions & 1 deletion gubernator/view_build.py
Expand Up @@ -30,7 +30,15 @@

def parse_junit(xml, filename):
"""Generate failed tests as a series of (name, duration, text, filename) tuples."""
tree = ET.fromstring(xml)
try:
tree = ET.fromstring(xml)
except ET.ParseError, e:
logging.exception('parse_junit failed for %s', filename)
try:
tree = ET.fromstring(re.sub(r'[\x00\x80-\xFF]+', '?', xml))
except ET.ParseError, e:
yield 'Gubernator Internal Fatal XML Parse Error', 0.0, str(e), filename
return
if tree.tag == 'testsuite':
for child in tree:
name = child.attrib['name']
Expand Down
16 changes: 16 additions & 0 deletions gubernator/view_build_test.py
Expand Up @@ -58,6 +58,22 @@ def test_testsuites(self):
def test_bad_xml(self):
self.assertEqual(self.parse('''<body />'''), [])

def test_corrupt_xml(self):
self.assertEqual(self.parse('<a>\xff</a>'), [])
failures = self.parse('''
<testsuites>
<testsuite name="a">
<testcase name="Corrupt" time="0">
<failure>something bad \xff</failure>
</testcase>
</testsuite>
</testsuites>''')
self.assertEqual(failures, [('a Corrupt', 0.0, 'something bad ?', 'fp')])

def test_not_xml(self):
failures = self.parse('\x01')
self.assertEqual(failures,
[(failures[0][0], 0.0, 'not well-formed (invalid token): line 1, column 0', 'fp')])

class BuildTest(main_test.TestBase):
# pylint: disable=too-many-public-methods
Expand Down

0 comments on commit 9f9e7af

Please sign in to comment.