html_diff: Handle empty differences between empty strings.

`rendered_content` in historical messages may be empty; examining the
history of them may thus require diff'ing two empty strings, which
itself produces an empty string.

Use `lxml.html.fragment_fromstring` to be able to successfully parse
these, rather than 500.

Part of #19559.
This commit is contained in:
Alex Vandiver
2021-09-30 15:14:28 -07:00
committed by Alex Vandiver
parent f6c78a35a4
commit b02754adec
2 changed files with 40 additions and 7 deletions

View File

@@ -6,7 +6,7 @@ from lxml.html.diff import htmldiff
def highlight_html_differences(s1: str, s2: str, msg_id: Optional[int] = None) -> str:
retval = htmldiff(s1, s2)
fragment = lxml.html.fromstring(retval)
fragment = lxml.html.fragment_fromstring(retval, create_parent=True)
for elem in fragment.cssselect("del"):
elem.tag = "span"