Skip to content

Commit

Permalink
[FIX] convert_html_fragment: Don't wrap full XMLs
Browse files Browse the repository at this point in the history
If the HTML string to convert is a fully XML compliant file including
the header `<?xml version="...?>`, the wrapping process is breaking the
final result, as the expected XML syntax doesn't include `?` in the
middle and lxml returns a weird result `<?xml version="...??>` with 2
interrogations.

With this commit, we are not wrapping if we detect the XML header.
  • Loading branch information
pedrobaeza committed Nov 7, 2023
1 parent c00a666 commit fb52701
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 fb52701

Please sign in to comment.