Skip to content

Commit

Permalink
Merge pull request #352 from Tecnativa/fix-convert_html_fragment-XML_…
Browse files Browse the repository at this point in the history
…compliant

[FIX] convert_html_fragment: Don't wrap full XMLs
  • Loading branch information
pedrobaeza authored Nov 8, 2023
2 parents c00a666 + fb52701 commit 939c6c2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions openupgradelib/openupgrade_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ def convert_html_fragment(html_string, replacements, pretty_print=True):
# For example: `<p><p/><p><p/>` is parsed as `<div><p><p/><p><p/></div>`
# So we force a custom wrapper tag on every parsed string so every xml receives
# the same treatment and we can extract it later with no harm
fragment = fromstring(
"<fragment_wrapper>{}</fragment_wrapper>".format(html_string)
)
if "<?xml " in html_string:
# XML compliant string - no need to wrap it.
fragment = fromstring(html_string)
else:
fragment = fromstring(
"<fragment_wrapper>{}</fragment_wrapper>".format(html_string)
)
except Exception:
logging.error("Failure converting string to DOM:\n%s", html_string)
raise
Expand Down

0 comments on commit 939c6c2

Please sign in to comment.