Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c90111f

Browse files
committed
#15970: xml.etree.ElementTree now serializes correctly the empty HTML elements "meta" and "param".
1 parent ab02db2 commit c90111f

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

Lib/test/test_xml_etree.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,26 @@ def check_issue10777():
18511851
>>> ET.register_namespace('test10777', 'http://myuri/')
18521852
"""
18531853

1854+
def check_html_empty_elems_serialization(self):
1855+
# issue 15970
1856+
# from http://www.w3.org/TR/html401/index/elements.html
1857+
"""
1858+
1859+
>>> empty_elems = ['AREA', 'BASE', 'BASEFONT', 'BR', 'COL', 'FRAME', 'HR',
1860+
... 'IMG', 'INPUT', 'ISINDEX', 'LINK', 'META', 'PARAM']
1861+
>>> elems = ''.join('<%s />' % elem for elem in empty_elems)
1862+
>>> serialize(ET.XML('<html>%s</html>' % elems), method='html')
1863+
'<html><AREA><BASE><BASEFONT><BR><COL><FRAME><HR><IMG><INPUT><ISINDEX><LINK><META><PARAM></html>'
1864+
>>> serialize(ET.XML('<html>%s</html>' % elems.lower()), method='html')
1865+
'<html><area><base><basefont><br><col><frame><hr><img><input><isindex><link><meta><param></html>'
1866+
>>> elems = ''.join('<%s></%s>' % (elem, elem) for elem in empty_elems)
1867+
>>> serialize(ET.XML('<html>%s</html>' % elems), method='html')
1868+
'<html><AREA><BASE><BASEFONT><BR><COL><FRAME><HR><IMG><INPUT><ISINDEX><LINK><META><PARAM></html>'
1869+
>>> serialize(ET.XML('<html>%s</html>' % elems.lower()), method='html')
1870+
'<html><area><base><basefont><br><col><frame><hr><img><input><isindex><link><meta><param></html>'
1871+
1872+
"""
1873+
18541874
# --------------------------------------------------------------------
18551875

18561876

Lib/xml/etree/ElementTree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ def _serialize_xml(write, elem, qnames, namespaces):
983983
write(_escape_cdata(elem.tail))
984984

985985
HTML_EMPTY = ("area", "base", "basefont", "br", "col", "frame", "hr",
986-
"img", "input", "isindex", "link", "meta" "param")
986+
"img", "input", "isindex", "link", "meta", "param")
987987

988988
try:
989989
HTML_EMPTY = set(HTML_EMPTY)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ Core and Builtins
120120
Library
121121
-------
122122

123+
- Issue #15970: xml.etree.ElementTree now serializes correctly the empty HTML
124+
elements 'meta' and 'param'.
125+
123126
- Issue #15842: the SocketIO.{readable,writable,seekable} methods now
124127
raise ValueError when the file-like object is closed. Patch by Alessandro
125128
Moura.

0 commit comments

Comments
 (0)