fix issue404 by more strict junitxml escape

This commit is contained in:
Ronny Pfannschmidt 2013-12-13 10:28:23 +01:00
parent 305cbecb34
commit e843b028e6
3 changed files with 25 additions and 8 deletions

View File

@ -1,3 +1,8 @@
Unreleased
-----------------------------------
- fix issue404 by always using the binary xml escape in the junitxml plugin
2.5.0 2.5.0
----------------------------------- -----------------------------------

View File

@ -130,36 +130,36 @@ class LogXML(object):
self.skipped += 1 self.skipped += 1
else: else:
fail = Junit.failure(message="test failure") fail = Junit.failure(message="test failure")
fail.append(unicode(report.longrepr)) fail.append(bin_xml_escape(report.longrepr))
self.append(fail) self.append(fail)
self.failed += 1 self.failed += 1
self._write_captured_output(report) self._write_captured_output(report)
def append_collect_failure(self, report): def append_collect_failure(self, report):
#msg = str(report.longrepr.reprtraceback.extraline) #msg = str(report.longrepr.reprtraceback.extraline)
self.append(Junit.failure(unicode(report.longrepr), self.append(Junit.failure(bin_xml_escape(report.longrepr),
message="collection failure")) message="collection failure"))
self.errors += 1 self.errors += 1
def append_collect_skipped(self, report): def append_collect_skipped(self, report):
#msg = str(report.longrepr.reprtraceback.extraline) #msg = str(report.longrepr.reprtraceback.extraline)
self.append(Junit.skipped(unicode(report.longrepr), self.append(Junit.skipped(bin_xml_escape(report.longrepr),
message="collection skipped")) message="collection skipped"))
self.skipped += 1 self.skipped += 1
def append_error(self, report): def append_error(self, report):
self.append(Junit.error(unicode(report.longrepr), self.append(Junit.error(bin_xml_escape(report.longrepr),
message="test setup failure")) message="test setup failure"))
self.errors += 1 self.errors += 1
def append_skipped(self, report): def append_skipped(self, report):
if hasattr(report, "wasxfail"): if hasattr(report, "wasxfail"):
self.append(Junit.skipped(unicode(report.wasxfail), self.append(Junit.skipped(bin_xml_escape(report.wasxfail),
message="expected test failure")) message="expected test failure"))
else: else:
filename, lineno, skipreason = report.longrepr filename, lineno, skipreason = report.longrepr
if skipreason.startswith("Skipped: "): if skipreason.startswith("Skipped: "):
skipreason = skipreason[9:] skipreason = bin_xml_escape(skipreason[9:])
self.append( self.append(
Junit.skipped("%s:%s: %s" % report.longrepr, Junit.skipped("%s:%s: %s" % report.longrepr,
type="pytest.skip", type="pytest.skip",
@ -193,7 +193,7 @@ class LogXML(object):
def pytest_internalerror(self, excrepr): def pytest_internalerror(self, excrepr):
self.errors += 1 self.errors += 1
data = py.xml.escape(excrepr) data = bin_xml_escape(excrepr)
self.tests.append( self.tests.append(
Junit.testcase( Junit.testcase(
Junit.error(data, message="internal error"), Junit.error(data, message="internal error"),

View File

@ -284,6 +284,19 @@ class TestPython:
if not sys.platform.startswith("java"): if not sys.platform.startswith("java"):
assert "hx" in fnode.toxml() assert "hx" in fnode.toxml()
def test_assertion_binchars(self, testdir):
"""this test did fail when the escaping wasnt strict"""
testdir.makepyfile("""
M1 = '\x01\x02\x03\x04'
M2 = '\x01\x02\x03\x05'
def test_str_compare():
assert M1 == M2
""")
result, dom = runandparse(testdir)
print dom.toxml()
def test_pass_captures_stdout(self, testdir): def test_pass_captures_stdout(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
def test_pass(): def test_pass():
@ -392,7 +405,6 @@ def test_nullbyte_replace(testdir):
text = xmlf.read() text = xmlf.read()
assert '#x0' in text assert '#x0' in text
def test_invalid_xml_escape(): def test_invalid_xml_escape():
# Test some more invalid xml chars, the full range should be # Test some more invalid xml chars, the full range should be
# tested really but let's just thest the edges of the ranges # tested really but let's just thest the edges of the ranges