Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use defusedxml for Parsing XML #554

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pyqrcode = "==1.2.1"
types-PyYAML = "==6.0.12.12"
docx2pdf = "==0.1.8"
lxml = "==5.2.2"
defusedxml = "==0.7.1"
types-defusedxml = "==0.7.0.20240218"

[requires]
python_version = "3.10"
79 changes: 49 additions & 30 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions scripts/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from typing import Any, Dict, Generator, List, Tuple, Union
from operator import itemgetter
from itertools import groupby
import defusedxml.ElementTree


class ConvertVars:
Expand Down Expand Up @@ -453,7 +454,7 @@ def get_replacement_data(
):
with open(file, "r", encoding="utf-8") as f:
try:
data = yaml.load(f, Loader=yaml.SafeLoader)
data = yaml.load(f, Loader=yaml.BaseLoader)
except yaml.YAMLError as e:
logging.info(f"Error loading yaml file: {file}. Error = {e}")
continue
Expand Down Expand Up @@ -961,7 +962,7 @@ def replace_text_in_xml_file(filename: str, replacement_dict: Dict[str, str]) ->
replacement_values = list(replacement_dict.items())

try:
tree = ElTree.parse(filename)
tree = defusedxml.ElementTree.parse(filename)
except ElTree.ParseError as e:
logging.error(f" --- parsing xml file: {filename}. error = {e}")
return
Expand Down
Loading