]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46786: Make ElementTree write the HTML tags embed, source, track, wbr as empty...
authorJannis Vajen <jvajen@gmail.com>
Sun, 27 Feb 2022 14:25:54 +0000 (15:25 +0100)
committerGitHub <noreply@github.com>
Sun, 27 Feb 2022 14:25:54 +0000 (15:25 +0100)
See https://html.spec.whatwg.org/multipage/syntax.html#void-elements
for reference.

Lib/test/test_xml_etree.py
Lib/xml/etree/ElementTree.py
Misc/NEWS.d/next/Library/2022-02-18-12-10-26.bpo-46786.P0xRvS.rst [new file with mode: 0644]

index c5292b5e9ef68c95f24958facf37ee8e2c052a5b..35d901f9d08244dd75f2f66391255118781fda0c 100644 (file)
@@ -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')
index e9409fd29a11572d51cdb0d3f41016f7a6348b0e..6059e2f592d2d065f38cdb76e30d5ef708149c44 100644 (file)
@@ -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
diff --git a/Misc/NEWS.d/next/Library/2022-02-18-12-10-26.bpo-46786.P0xRvS.rst b/Misc/NEWS.d/next/Library/2022-02-18-12-10-26.bpo-46786.P0xRvS.rst
new file mode 100644 (file)
index 0000000..e0384a8
--- /dev/null
@@ -0,0 +1,2 @@
+The HTML serialisation in xml.etree.ElementTree now writes ``embed``,
+``source``, ``track`` and ``wbr`` as empty tags, as defined in HTML 5.