Skip to content

Commit bf2bfc2

Browse files
committed
add log protection
Signed-off-by: Hake Huang <[email protected]>
1 parent ea80f34 commit bf2bfc2

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

scripts/results_verification.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,22 @@ def check_file_size(file_path, max_size=5):
3636
return bool(file_size <= max_size)
3737

3838

39+
def escape_xml_illegal_chars(s):
40+
return (s.replace(r" ", "")
41+
.replace(r" ", ""))
42+
43+
3944
def check_name(file_path):
4045
"""
4146
Check if the name of the file corresponds with the platform name in the report
4247
4348
:param file_path: path of junit xml report from twister to be checked
4449
"""
4550
platform = file_path.name[:-4]
46-
summary = ET.parse(file_path).getroot()[0]
51+
with open(file_path, 'r', encoding='utf-8') as file:
52+
xml_string = file.read()
53+
xml_string_escaped = escape_xml_illegal_chars(xml_string)
54+
summary = ET.fromstring(xml_string_escaped)[0]
4755
name_in_report = summary.attrib['name']
4856
name_in_report_norm = "_".join(name_in_report.split('/'))
4957
return bool(platform == name_in_report_norm)
@@ -57,7 +65,10 @@ def check_attribute_value(file_path=None, item=None, max_value=None):
5765
:param item: attribute to be verified
5866
:param max_value: max value of the given attribute
5967
"""
60-
summary = ET.parse(file_path).getroot()[0]
68+
with open(file_path, 'r', encoding='utf-8') as file:
69+
xml_string = file.read()
70+
xml_string_escaped = escape_xml_illegal_chars(xml_string)
71+
summary = ET.fromstring(xml_string_escaped)[0]
6172
item_count = int(summary.attrib[item])
6273
return bool(item_count <= max_value)
6374

@@ -69,7 +80,10 @@ def check_version_consistent(file_path=None, version=None):
6980
:param file_path: junit xml report from twister
7081
:param version: expected version of zephyr
7182
"""
72-
testsuite = ET.parse(file_path).getroot()[0]
83+
with open(file_path, 'r', encoding='utf-8') as file:
84+
xml_string = file.read()
85+
xml_string_escaped = escape_xml_illegal_chars(xml_string)
86+
testsuite = ET.fromstring(xml_string_escaped)[0]
7387
properties = testsuite[0]
7488
for property in properties:
7589
if property.attrib['name'] == "version":

0 commit comments

Comments
 (0)