From 6d6fb3aa9f641c133472f2bbb7565dde6e712e87 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Wed, 19 Sep 2012 08:11:03 +0300 Subject: [PATCH] #15970: xml.etree.ElementTree now serializes correctly the empty HTML elements "meta" and "param". --- Lib/test/test_xml_etree.py | 20 ++++++++++++++++++++ Lib/xml/etree/ElementTree.py | 2 +- Misc/NEWS | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index f1a774ae94d..4e161ca2f3a 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -1822,6 +1822,26 @@ def check_issue6565(): """ +def check_html_empty_elems_serialization(self): + # issue 15970 + # from http://www.w3.org/TR/html401/index/elements.html + """ + + >>> empty_elems = ['AREA', 'BASE', 'BASEFONT', 'BR', 'COL', 'FRAME', 'HR', + ... 'IMG', 'INPUT', 'ISINDEX', 'LINK', 'META', 'PARAM'] + >>> elems = ''.join('<%s />' % elem for elem in empty_elems) + >>> serialize(ET.XML('%s' % elems), method='html') + '

' + >>> serialize(ET.XML('%s' % elems.lower()), method='html') + '

' + >>> elems = ''.join('<%s>' % (elem, elem) for elem in empty_elems) + >>> serialize(ET.XML('%s' % elems), method='html') + '

' + >>> serialize(ET.XML('%s' % elems.lower()), method='html') + '

' + + """ + # -------------------------------------------------------------------- diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index 2b0cf0c7833..d8ec67a90eb 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -945,7 +945,7 @@ def _serialize_xml(write, elem, encoding, qnames, namespaces): write(_escape_cdata(elem.tail, encoding)) HTML_EMPTY = ("area", "base", "basefont", "br", "col", "frame", "hr", - "img", "input", "isindex", "link", "meta" "param") + "img", "input", "isindex", "link", "meta", "param") try: HTML_EMPTY = set(HTML_EMPTY) diff --git a/Misc/NEWS b/Misc/NEWS index f3d6fc359b9..a082a24382f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -103,6 +103,9 @@ Core and Builtins Library ------- +- Issue #15970: xml.etree.ElementTree now serializes correctly the empty HTML + elements 'meta' and 'param'. + - Issue #15676: Now "mmap" check for empty files before doing the offset check. Patch by Steven Willis.