Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54ad7e3

Browse files
committed
Issue #18347: ElementTree's html serializer now preserves the case of closing tags.
1 parent be9c841 commit 54ad7e3

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

Lib/test/test_xml_etree.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,13 @@ def test_methods(self):
751751
'<html><link><script>1 < 2</script></html>\n')
752752
self.assertEqual(serialize(e, method="text"), '1 < 2\n')
753753

754+
def test_issue18347(self):
755+
e = ET.XML('<html><CamelCase>text</CamelCase></html>')
756+
self.assertEqual(serialize(e),
757+
'<html><CamelCase>text</CamelCase></html>')
758+
self.assertEqual(serialize(e, method="html"),
759+
'<html><CamelCase>text</CamelCase></html>')
760+
754761
def test_entity(self):
755762
# Test entity handling.
756763

Lib/xml/etree/ElementTree.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,15 +1039,15 @@ def _serialize_html(write, elem, qnames, namespaces):
10391039
# FIXME: handle boolean attributes
10401040
write(" %s=\"%s\"" % (qnames[k], v))
10411041
write(">")
1042-
tag = tag.lower()
1042+
ltag = tag.lower()
10431043
if text:
1044-
if tag == "script" or tag == "style":
1044+
if ltag == "script" or ltag == "style":
10451045
write(text)
10461046
else:
10471047
write(_escape_cdata(text))
10481048
for e in elem:
10491049
_serialize_html(write, e, qnames, None)
1050-
if tag not in HTML_EMPTY:
1050+
if ltag not in HTML_EMPTY:
10511051
write("</" + tag + ">")
10521052
if elem.tail:
10531053
write(_escape_cdata(elem.tail))

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ Core and Builtins
4141
Library
4242
-------
4343

44+
- Issue #18347: ElementTree's html serializer now preserves the case of
45+
closing tags.
46+
4447
- Issue #17261: Ensure multiprocessing's proxies use proper address.
4548

4649
- Issue #18343: faulthandler.register() now keeps the previous signal handler

0 commit comments

Comments
 (0)