From: Christian Heimes Date: Thu, 4 Jul 2013 23:39:49 +0000 (+0200) Subject: Issue #18347: ElementTree's html serializer now preserves the case of closing tags. X-Git-Tag: v3.4.0a1~327^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=54ad7e39dfe429795cc908a9a03a94c485c87cc2;p=python Issue #18347: ElementTree's html serializer now preserves the case of closing tags. --- diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 4a586bd0c6..4c2e26f61e 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -751,6 +751,13 @@ class ElementTreeTest(unittest.TestCase): '\n') self.assertEqual(serialize(e, method="text"), '1 < 2\n') + def test_issue18347(self): + e = ET.XML('text') + self.assertEqual(serialize(e), + 'text') + self.assertEqual(serialize(e, method="html"), + 'text') + def test_entity(self): # Test entity handling. diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index 4c73303819..f1a6c99059 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -1039,15 +1039,15 @@ def _serialize_html(write, elem, qnames, namespaces): # FIXME: handle boolean attributes write(" %s=\"%s\"" % (qnames[k], v)) write(">") - tag = tag.lower() + ltag = tag.lower() if text: - if tag == "script" or tag == "style": + if ltag == "script" or ltag == "style": write(text) else: write(_escape_cdata(text)) for e in elem: _serialize_html(write, e, qnames, None) - if tag not in HTML_EMPTY: + if ltag not in HTML_EMPTY: write("") if elem.tail: write(_escape_cdata(elem.tail)) diff --git a/Misc/NEWS b/Misc/NEWS index 515cb8d82e..d0f2462f7f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -41,6 +41,9 @@ Core and Builtins Library ------- +- Issue #18347: ElementTree's html serializer now preserves the case of + closing tags. + - Issue #17261: Ensure multiprocessing's proxies use proper address. - Issue #18343: faulthandler.register() now keeps the previous signal handler