libtest: Stricter XML validation

Expect the entire input to be a single XML document, instead of
reading it line by line. This detects trailing junk better.
This commit is contained in:
Oleksii Lozovskyi 2025-12-13 16:19:33 +09:00
parent cc3eee7fbe
commit e39e127bd0

View file

@ -13,10 +13,10 @@
import sys
import xml.etree.ElementTree as ET
# Try to decode line in order to ensure it is a valid XML document
for line in sys.stdin:
try:
ET.fromstring(line)
except ET.ParseError:
print("Invalid xml: %r" % line)
raise
# Read the entire output and try to decode it as XML.
junit = sys.stdin.read()
try:
ET.fromstring(junit)
except ET.ParseError:
print("Invalid xml: %r" % junit)
raise