Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2729 from pypeclub/bugfix/oiio_xml_parse_ampresan…
Browse files Browse the repository at this point in the history
…d_values

General: Fix loading of unused chars in xml format
  • Loading branch information
iLLiCiTiT authored Feb 15, 2022
2 parents 1ae7201 + 985a6c8 commit 1b1c614
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions openpype/lib/transcoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"deep",
"subimages",
}

XML_CHAR_REF_REGEX_HEX = re.compile(r"&#x?[0-9a-fA-F]+;")

# Regex to parse array attributes
ARRAY_TYPE_REGEX = re.compile(r"^(int|float|string)\[\d+\]$")

Expand Down Expand Up @@ -191,6 +194,17 @@ def parse_oiio_xml_output(xml_string, logger=None):
if not xml_string:
return output

# Fix values with ampresand (lazy fix)
# - oiiotool exports invalid xml which ElementTree can't handle
# e.g. ""
# WARNING: this will affect even valid character entities. If you need
# those values correctly, this must take care of valid character ranges.
# See https://github.com/pypeclub/OpenPype/pull/2729
matches = XML_CHAR_REF_REGEX_HEX.findall(xml_string)
for match in matches:
new_value = match.replace("&", "&")
xml_string = xml_string.replace(match, new_value)

if logger is None:
logger = logging.getLogger("OIIO-xml-parse")

Expand Down

0 comments on commit 1b1c614

Please sign in to comment.