summaryrefslogtreecommitdiffstats
path: root/Lib/test/libregrtest/testresult.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-07-01 08:30:33 (GMT)
committerGitHub <noreply@github.com>2024-07-01 08:30:33 (GMT)
commitaf8c3d7a26d605099f5b3406a8d33ecddb77e8fb (patch)
treeec814ccede37647ad55f4518d8a6ee26ee3d9abe /Lib/test/libregrtest/testresult.py
parentf80376b129ad947263a6b03a6c3a874e9f8706e6 (diff)
downloadcpython-af8c3d7a26d605099f5b3406a8d33ecddb77e8fb.zip
cpython-af8c3d7a26d605099f5b3406a8d33ecddb77e8fb.tar.gz
cpython-af8c3d7a26d605099f5b3406a8d33ecddb77e8fb.tar.bz2
gh-121188: Sanitize invalid XML characters in regrtest (#121195)
When creating the JUnit XML file, regrtest now escapes characters which are invalid in XML, such as the chr(27) control character used in ANSI escape sequences.
Diffstat (limited to 'Lib/test/libregrtest/testresult.py')
-rw-r--r--Lib/test/libregrtest/testresult.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/test/libregrtest/testresult.py b/Lib/test/libregrtest/testresult.py
index de23fdd..1820f35 100644
--- a/Lib/test/libregrtest/testresult.py
+++ b/Lib/test/libregrtest/testresult.py
@@ -9,6 +9,7 @@ import time
import traceback
import unittest
from test import support
+from test.libregrtest.utils import sanitize_xml
class RegressionTestResult(unittest.TextTestResult):
USE_XML = False
@@ -65,23 +66,24 @@ class RegressionTestResult(unittest.TextTestResult):
if capture:
if self._stdout_buffer is not None:
stdout = self._stdout_buffer.getvalue().rstrip()
- ET.SubElement(e, 'system-out').text = stdout
+ ET.SubElement(e, 'system-out').text = sanitize_xml(stdout)
if self._stderr_buffer is not None:
stderr = self._stderr_buffer.getvalue().rstrip()
- ET.SubElement(e, 'system-err').text = stderr
+ ET.SubElement(e, 'system-err').text = sanitize_xml(stderr)
for k, v in args.items():
if not k or not v:
continue
+
e2 = ET.SubElement(e, k)
if hasattr(v, 'items'):
for k2, v2 in v.items():
if k2:
- e2.set(k2, str(v2))
+ e2.set(k2, sanitize_xml(str(v2)))
else:
- e2.text = str(v2)
+ e2.text = sanitize_xml(str(v2))
else:
- e2.text = str(v)
+ e2.text = sanitize_xml(str(v))
@classmethod
def __makeErrorDict(cls, err_type, err_value, err_tb):