diff options
author | Christian Heimes <christian@cheimes.de> | 2013-07-04 23:39:49 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2013-07-04 23:39:49 (GMT) |
commit | 54ad7e39dfe429795cc908a9a03a94c485c87cc2 (patch) | |
tree | 453c78e1fa5cd4f12bd09314a418f9df238a1f34 /Lib | |
parent | be9c8414945dc15c079d07a0b84597142ea41511 (diff) | |
download | cpython-54ad7e39dfe429795cc908a9a03a94c485c87cc2.zip cpython-54ad7e39dfe429795cc908a9a03a94c485c87cc2.tar.gz cpython-54ad7e39dfe429795cc908a9a03a94c485c87cc2.tar.bz2 |
Issue #18347: ElementTree's html serializer now preserves the case of closing tags.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_xml_etree.py | 7 | ||||
-rw-r--r-- | Lib/xml/etree/ElementTree.py | 6 |
2 files changed, 10 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): '<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. 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("</" + tag + ">") if elem.tail: write(_escape_cdata(elem.tail)) |