]> granicus.if.org Git - python/commitdiff
Issue #18347: ElementTree's html serializer now preserves the case of closing tags.
authorChristian Heimes <christian@cheimes.de>
Thu, 4 Jul 2013 23:39:49 +0000 (01:39 +0200)
committerChristian Heimes <christian@cheimes.de>
Thu, 4 Jul 2013 23:39:49 +0000 (01:39 +0200)
Lib/test/test_xml_etree.py
Lib/xml/etree/ElementTree.py
Misc/NEWS

index 4a586bd0c609145811ab03892f09a09306536f4a..4c2e26f61e4b71d6aa42c79509fc57604c9fbb3c 100644 (file)
@@ -751,6 +751,13 @@ class ElementTreeTest(unittest.TestCase):
                 '<html><link><script>1 < 2</script></html>\n')
         self.assertEqual(serialize(e, method="text"), '1 < 2\n')
 
+    def test_issue18347(self):
+        e = ET.XML('<html><CamelCase>text</CamelCase></html>')
+        self.assertEqual(serialize(e),
+                '<html><CamelCase>text</CamelCase></html>')
+        self.assertEqual(serialize(e, method="html"),
+                '<html><CamelCase>text</CamelCase></html>')
+
     def test_entity(self):
         # Test entity handling.
 
index 4c73303819ec959dcbc8b2a69887030673d60f39..f1a6c990598f4d1af5e0087b81d99acf6ca23d72 100644 (file)
@@ -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("</" + tag + ">")
     if elem.tail:
         write(_escape_cdata(elem.tail))
index 515cb8d82e9e4ed6955779ce0e20cb28bdbed179..d0f2462f7f54bfb2853d8a876dd51b4c9ac223e9 100644 (file)
--- 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