Skip to content

Commit 20d4669

Browse files
committed
Issue python#18347: ElementTree's html serializer now preserves the case of closing tags.
1 parent 0c503c2 commit 20d4669

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎Lib/test/test_xml_etree.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,16 @@ def bug_200709_iter_comment():
17691769
17701770
"""
17711771

1772+
def bug_18347():
1773+
"""
1774+
1775+
>>> e = ET.XML('<html><CamelCase>text</CamelCase></html>')
1776+
>>> serialize(e)
1777+
'<html><CamelCase>text</CamelCase></html>'
1778+
>>> serialize(e, method="html")
1779+
'<html><CamelCase>text</CamelCase></html>'
1780+
"""
1781+
17721782
# --------------------------------------------------------------------
17731783
# reported on bugs.python.org
17741784

‎Lib/xml/etree/ElementTree.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -988,15 +988,15 @@ def _serialize_html(write, elem, encoding, qnames, namespaces):
988988
# FIXME: handle boolean attributes
989989
write(" %s=\"%s\"" % (qnames[k], v))
990990
write(">")
991-
tag = tag.lower()
991+
ltag = tag.lower()
992992
if text:
993-
if tag == "script" or tag == "style":
993+
if ltag == "script" or ltag == "style":
994994
write(_encode(text, encoding))
995995
else:
996996
write(_escape_cdata(text, encoding))
997997
for e in elem:
998998
_serialize_html(write, e, encoding, qnames, None)
999-
if tag not in HTML_EMPTY:
999+
if ltag not in HTML_EMPTY:
10001000
write("</" + tag + ">")
10011001
if elem.tail:
10021002
write(_escape_cdata(elem.tail, encoding))

‎Misc/NEWS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Core and Builtins
2424
Library
2525
-------
2626

27+
- Issue #18347: ElementTree's html serializer now preserves the case of
28+
closing tags.
29+
2730
- Issue #17261: Ensure multiprocessing's proxies use proper address.
2831

2932
- Issue #17097: Make multiprocessing ignore EINTR.

0 commit comments

Comments
 (0)