From ace1a53d486f69b8c15e382414a2be25c338727c Mon Sep 17 00:00:00 2001 From: Vincent Shen Date: Wed, 21 Feb 2024 16:44:19 -0800 Subject: [PATCH] OCP4: use utf-8 as default xml encoding This commit make UTF-8 as default xml encoding. In a recent change, when writing xccdf xml file, it uses the output encoding US-ASCII as default if not set, however this causes issues in Compliance Operator parser, using US-ASCII, the parser is not able to get the prefix of xml node, therefore crash the parser pod. --- build-scripts/build_xccdf.py | 2 +- build-scripts/compose_ds.py | 4 ++-- ssg/build_yaml.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build-scripts/build_xccdf.py b/build-scripts/build_xccdf.py index a13a013e478..25d88f7dda6 100644 --- a/build-scripts/build_xccdf.py +++ b/build-scripts/build_xccdf.py @@ -97,7 +97,7 @@ def link_benchmark(loader, xccdftree, args, benchmark=None): if ocil is not None: link_ocil(xccdftree, checks, args.ocil, ocil) - ssg.xml.ElementTree.ElementTree(xccdftree).write(args.xccdf) + ssg.xml.ElementTree.ElementTree(xccdftree).write(args.xccdf, encoding="utf-8") def get_path(path, file_name): diff --git a/build-scripts/compose_ds.py b/build-scripts/compose_ds.py index decdc19364f..0b36a8a3668 100755 --- a/build-scripts/compose_ds.py +++ b/build-scripts/compose_ds.py @@ -282,10 +282,10 @@ def upgrade_ds_to_scap_13(ds): def _store_ds(ds, output_13, output_12): if output_12: - ds.write(output_12, xml_declaration=True) + ds.write(output_12, xml_declaration=True, encoding="utf-8") ds_13 = upgrade_ds_to_scap_13(ds) - ds_13.write(output_13, xml_declaration=True) + ds_13.write(output_13, xml_declaration=True, encoding="utf-8") def append_id_to_file_name(path, id_): diff --git a/ssg/build_yaml.py b/ssg/build_yaml.py index 51975252325..5f56f1c5f94 100644 --- a/ssg/build_yaml.py +++ b/ssg/build_yaml.py @@ -426,7 +426,7 @@ def to_xml_element(self, env_yaml=None, product_cpes=None): def to_file(self, file_name, env_yaml=None): root = self.to_xml_element(env_yaml) tree = ET.ElementTree(root) - tree.write(file_name) + tree.write(file_name, encoding="utf-8") def add_value(self, value): if value is None: @@ -1590,7 +1590,7 @@ def export_ocil_to_file(self, filename): if root is None: return tree = ET.ElementTree(root) - tree.write(filename, xml_declaration=True) + tree.write(filename, encoding="utf-8", xml_declaration=True) class Platform(XCCDFEntity):