From 54ad7e39dfe429795cc908a9a03a94c485c87cc2 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 5 Jul 2013 01:39:49 +0200 Subject: Issue #18347: ElementTree's html serializer now preserves the case of closing tags. --- Lib/test/test_xml_etree.py | 7 +++++++ Lib/xml/etree/ElementTree.py | 6 +++--- Misc/NEWS | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 4a586bd..4c2e26f 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 4c73303..f1a6c99 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 515cb8d..d0f2462 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 -- cgit v0.12