Skip to content

Commit

Permalink
feat(xml): dont resolve entities when parsing xml
Browse files Browse the repository at this point in the history
  • Loading branch information
RDWimmers committed Dec 22, 2023
1 parent 1e343da commit 1675457
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/pygef/broxml/parse_bore.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from pygef.bore import BoreData
from pygef.broxml import resolvers
from pygef.broxml.xml_parser import read_xml
from pygef.broxml.xml_parser import BaseParser, read_xml

# maps keyword argument to:
# xpath: query passed to elementree.find
Expand Down Expand Up @@ -136,9 +136,9 @@

def read_bore(file: io.BytesIO | Path | str) -> list[BoreData]:
if isinstance(file, str) and not os.path.exists(file):
root = etree.fromstring(file).getroot()
root = etree.fromstring(file, parser=BaseParser).getroot()
else:
root = etree.parse(file).getroot()
root = etree.parse(file, parser=BaseParser).getroot()
match = re.compile(r"xsd/.*/(\d\.\d)")
matched = match.search(root.nsmap["bhrgtcom"])

Expand Down
6 changes: 3 additions & 3 deletions src/pygef/broxml/parse_cpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from lxml import etree

from pygef.broxml import resolvers
from pygef.broxml.xml_parser import read_xml
from pygef.broxml.xml_parser import BaseParser, read_xml
from pygef.cpt import CPTData

# maps keyword argument to:
Expand Down Expand Up @@ -196,7 +196,7 @@

def read_cpt(file: io.BytesIO | Path | str) -> list[CPTData]:
if isinstance(file, str) and not os.path.exists(file):
root = etree.fromstring(file).getroot()
root = etree.fromstring(file, parser=BaseParser).getroot()
else:
root = etree.parse(file).getroot()
root = etree.parse(file, parser=BaseParser).getroot()
return read_xml(root, CPTData, CPT_ATTRIBS, "dispatchDocument")
2 changes: 2 additions & 0 deletions src/pygef/broxml/xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

T = TypeVar("T", CPTData, BoreData)

BaseParser = etree.XMLParser(resolve_entities=False, dtd_validation=False)


def read_xml(
root: etree.Element,
Expand Down

0 comments on commit 1675457

Please sign in to comment.