diff options
author | Jannis Vajen <jvajen@gmail.com> | 2022-02-27 14:25:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-27 14:25:54 (GMT) |
commit | 345572a1a0263076081020524016eae867677cac (patch) | |
tree | bd8a0d74d452e7cc98a111198c7ed24a581255d7 /Lib | |
parent | 5a1c637ec6264790d3cfeef46815c62c32b510f3 (diff) | |
download | cpython-345572a1a0263076081020524016eae867677cac.zip cpython-345572a1a0263076081020524016eae867677cac.tar.gz cpython-345572a1a0263076081020524016eae867677cac.tar.bz2 |
bpo-46786: Make ElementTree write the HTML tags embed, source, track, wbr as empty tags (GH-31406)
See https://html.spec.whatwg.org/multipage/syntax.html#void-elements
for reference.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_xml_etree.py | 5 | ||||
-rw-r--r-- | Lib/xml/etree/ElementTree.py | 10 |
2 files changed, 6 insertions, 9 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index c5292b5..35d901f 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -1350,8 +1350,9 @@ class ElementTreeTest(unittest.TestCase): def test_html_empty_elems_serialization(self): # issue 15970 # from http://www.w3.org/TR/html401/index/elements.html - for element in ['AREA', 'BASE', 'BASEFONT', 'BR', 'COL', 'FRAME', 'HR', - 'IMG', 'INPUT', 'ISINDEX', 'LINK', 'META', 'PARAM']: + for element in ['AREA', 'BASE', 'BASEFONT', 'BR', 'COL', 'EMBED', 'FRAME', + 'HR', 'IMG', 'INPUT', 'ISINDEX', 'LINK', 'META', 'PARAM', + 'SOURCE', 'TRACK', 'WBR']: for elem in [element, element.lower()]: expected = '<%s>' % elem serialized = serialize(ET.XML('<%s />' % elem), method='html') diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index e9409fd..6059e2f 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -918,13 +918,9 @@ def _serialize_xml(write, elem, qnames, namespaces, if elem.tail: write(_escape_cdata(elem.tail)) -HTML_EMPTY = ("area", "base", "basefont", "br", "col", "frame", "hr", - "img", "input", "isindex", "link", "meta", "param") - -try: - HTML_EMPTY = set(HTML_EMPTY) -except NameError: - pass +HTML_EMPTY = {"area", "base", "basefont", "br", "col", "embed", "frame", "hr", + "img", "input", "isindex", "link", "meta", "param", "source", + "track", "wbr"} def _serialize_html(write, elem, qnames, namespaces, **kwargs): tag = elem.tag |