Merge pull request #2729 from pypeclub/bugfix/oiio_xml_parse_ampresand_values

General: Fix loading of unused chars in xml format
This commit is contained in:
Jakub Trllo 2022-02-15 18:01:43 +01:00 committed by GitHub
commit 1b1c6145df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,6 +30,9 @@ INT_TAGS = {
"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+\]$")
@ -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")