Skip to content

Commit

Permalink
resolve entities in opf so that xmlencoding and decoding is more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhendricks committed Nov 21, 2020
1 parent 0ad2b79 commit 4286671
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Sigil-1.4.2
- fix bug in multiple language spellchecking dialog word lookup
when no language attributes used
- update de, nl, sv, ko, ru translations that missed the Sigil 1.4.0 initial release
- fix bug in OPF metadata attributes that use named entities

Sigil-1.4.1
Bug Fixes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def default_parser(self, encoding):
if self._default_parser is not None:
return self._default_parser
return etree.XMLParser(
target=self, strip_cdata=False, recover=True, encoding=encoding, resolve_entities=False)
target=self, strip_cdata=False, recover=True, encoding=encoding, resolve_entities=True)

def parser_for(self, encoding):
# Use the default parser.
Expand All @@ -77,7 +77,7 @@ def parser_for(self, encoding):
if isinstance(parser, Callable):
# Instantiate the parser with default arguments
if self.is_xml:
parser = parser(target=self, strip_cdata=False, encoding=encoding, resolve_entities=False)
parser = parser(target=self, strip_cdata=False, encoding=encoding, resolve_entities=True)
else:
parser = parser(target=self, strip_cdata=False, encoding=encoding)
return parser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class PageElement(object):

XML_FORMATTERS = {
"html" : EntitySubstitution.substitute_html,
"minimal" : EntitySubstitution.substitute_xml,
"minimal" : EntitySubstitution.substitute_xml_containing_entities,
None : None
}

Expand Down
6 changes: 3 additions & 3 deletions src/Resource_Files/python3lib/xmlprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _well_formed(data):
if isinstance(newdata, str):
newdata = newdata.encode('utf-8')
try:
parser = etree.XMLParser(encoding='utf-8', recover=False, resolve_entities=False)
parser = etree.XMLParser(encoding='utf-8', recover=False, resolve_entities=True)
tree = etree.parse(BytesIO(newdata), parser)
except Exception:
result = False
Expand All @@ -53,7 +53,7 @@ def _reformat(data):
if isinstance(newdata, str):
newdata = newdata.encode('utf-8')
parser = etree.XMLParser(encoding='utf-8', recover=True, ns_clean=True,
remove_comments=True, remove_pis=True, strip_cdata=True, resolve_entities=False)
remove_comments=True, remove_pis=True, strip_cdata=True, resolve_entities=True)
tree = etree.parse(BytesIO(newdata), parser)
newdata = etree.tostring(tree.getroot(),encoding='UTF-8', xml_declaration=False)
return newdata
Expand Down Expand Up @@ -125,7 +125,7 @@ def WellFormedXMLErrorCheck(data, mtype=""):
column = "-1"
message = "well-formed"
try:
parser = etree.XMLParser(encoding='utf-8', recover=False, resolve_entities=False)
parser = etree.XMLParser(encoding='utf-8', recover=False, resolve_entities=True)
tree = etree.parse(BytesIO(newdata), parser)
except Exception:
line = "0"
Expand Down

0 comments on commit 4286671

Please sign in to comment.