1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-05-04 17:32:58 +00:00

xml: add huge_tree option to support large XML files (#11940)

* feat(xml): add huge_tree option to support large XML files

Add the huge_tree parameter (bool, default false) which passes huge_tree=True
to lxml's XMLParser, disabling libxml2's internal size restrictions on text
nodes and document depth.

Fixes #4897

* fix(xml): add changelog fragment for PR 11940
This commit is contained in:
Alexei Znamensky 2026-05-02 10:42:13 +12:00 committed by GitHub
parent a6dd7ce58c
commit edcc906cc6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View file

@ -121,6 +121,13 @@ options:
- Note that this might break your XML file if text values contain characters that could be interpreted as XML.
type: bool
default: false
huge_tree:
description:
- Disable libxml2 security restrictions on XML node size or document depth, allowing processing of very large XML files.
- This option should only be activated when needed, as it disables internal safety limits.
type: bool
default: false
version_added: "13.0.0"
insertbefore:
description:
- Add additional child-element(s) before the first selected element for a given O(xpath).
@ -875,6 +882,7 @@ def main():
input_type=dict(type="str", default="yaml", choices=["xml", "yaml"]),
backup=dict(type="bool", default=False),
strip_cdata_tags=dict(type="bool", default=False),
huge_tree=dict(type="bool", default=False),
insertbefore=dict(type="bool", default=False),
insertafter=dict(type="bool", default=False),
),
@ -918,6 +926,7 @@ def main():
print_match = module.params["print_match"]
count = module.params["count"]
strip_cdata_tags = module.params["strip_cdata_tags"]
huge_tree = module.params["huge_tree"]
insertbefore = module.params["insertbefore"]
insertafter = module.params["insertafter"]
@ -950,7 +959,7 @@ def main():
# Try to parse in the target XML file
try:
parser = etree.XMLParser(remove_blank_text=pretty_print, strip_cdata=strip_cdata_tags)
parser = etree.XMLParser(remove_blank_text=pretty_print, strip_cdata=strip_cdata_tags, huge_tree=huge_tree)
doc = etree.parse(infile, parser)
except etree.XMLSyntaxError as e:
module.fail_json(msg=f"Error while parsing document: {xml_file or 'xml_string'} ({e})")