-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strings are not properly escaped in JUnit XML reports #163
Comments
You might want to take a look at, for example, https://github.com/xmlrunner/unittest-xml-reporting from the Python ecosystem to see how it handles this situation: import unittest
class TestRepro(unittest.TestCase):
def test_str_compare_null_byte(self):
actual = "q\u0000\u0000\u0002w\u0000"
expected = "q\u0000\u0000\u0002w\u0000\u0000"
self.assertEqual(actual, expected)
if __name__ == '__main__':
unittest.main() Make sure to $ python -m xmlrunner --outsuffix '' 2>&1 | cat --show-nonprinting
Running tests...
----------------------------------------------------------------------
F
======================================================================
FAIL [0.001s]: test_str_compare_null_byte (test_repro.TestRepro.test_str_compare_null_byte)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\temp\ks-experiments\luaunit-bug\test_repro.py", line 7, in test_str_compare_null_byte
self.assertEqual(actual, expected)
AssertionError: 'q\x00\x00\x02w\x00' != 'q\x00\x00\x02w\x00\x00'
- q^@^@^Bw^@
+ q^@^@^Bw^@^@
? +
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (failures=1)
Generating XML reports...
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="test_repro.TestRepro" tests="1" file="test_repro.py" time="0.001" timestamp="2024-07-25T17:03:59" failures="1" errors="0" skipped="0">
<testcase classname="test_repro.TestRepro" name="test_str_compare_null_byte" time="0.001" timestamp="2024-07-25T17:03:59" file="test_repro.py" line="4">
<failure type="AssertionError" message="'q\x00\x00\x02w\x00' != 'q\x00\x00\x02w\x00\x00'
- qw
+ qw
? +
"><![CDATA[Traceback (most recent call last):
File "C:\temp\ks-experiments\luaunit-bug\test_repro.py", line 7, in test_str_compare_null_byte
self.assertEqual(actual, expected)
AssertionError: 'q\x00\x00\x02w\x00' != 'q\x00\x00\x02w\x00\x00'
- qw
+ qw
? +
]]></failure>
</testcase>
</testsuite> Note that the assertion failure is escaped ( It also tries to display some kind of vertical diff with that I checked that the generated $ xxd -ps -c 1 TEST-test_repro.TestRepro.xml | sort -u
09
0a
20
(...)
79 (the
|
Reproduction code:
test_reproducer.lua
The problem is that the JUnit XML reports will also (like the console output) contain these characters unescaped, resulting in invalid XML that the XML parsers I've tried refuse to read:
$ cat --show-nonprinting report.xml
I tried:
Ruby
parse_xml.rb
Console output
Python:
pip install defusedxml
parse_xml.py
Console output
xmllint
(manpage, available on Ubuntu in the libxml2-utils package)Console output
As you can see, all of these reject the XML report with some kind of error, indicating that it is not well-formed XML.
The text was updated successfully, but these errors were encountered: