-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
gh-149489: Fix ElementTree serialization to HTML #149490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e41d61c
a9795d1
0f35342
e111ef9
752f4e7
57b5739
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -917,17 +917,20 @@ def _serialize_xml(write, elem, qnames, namespaces, | |
| if elem.tail: | ||
| write(_escape_cdata(elem.tail)) | ||
|
|
||
| _CDATA_CONTENT_ELEMENTS = {"script", "style", "xmp", "iframe", "noembed", | ||
| "noframes", "plaintext"} | ||
|
|
||
| HTML_EMPTY = {"area", "base", "basefont", "br", "col", "embed", "frame", "hr", | ||
| "img", "input", "isindex", "link", "meta", "param", "source", | ||
| "track", "wbr"} | ||
| "track", "wbr", "plaintext"} | ||
|
|
||
| def _serialize_html(write, elem, qnames, namespaces, **kwargs): | ||
| tag = elem.tag | ||
| text = elem.text | ||
| if tag is Comment: | ||
| write("<!--%s-->" % _escape_cdata(text)) | ||
| write("<!--%s-->" % text) | ||
|
Comment on lines
930
to
+931
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit late to the party, but what happens if |
||
| elif tag is ProcessingInstruction: | ||
| write("<?%s?>" % _escape_cdata(text)) | ||
| write("<?%s?>" % text) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess same question here -- what if |
||
| else: | ||
| tag = qnames[tag] | ||
| if tag is None: | ||
|
|
@@ -951,16 +954,19 @@ def _serialize_html(write, elem, qnames, namespaces, **kwargs): | |
| for k, v in items: | ||
| if isinstance(k, QName): | ||
| k = k.text | ||
| if isinstance(v, QName): | ||
| v = qnames[v.text] | ||
| k = qnames[k] | ||
| if v is None: | ||
| write(" %s" % k) # empty attr | ||
| else: | ||
| v = _escape_attrib_html(v) | ||
| # FIXME: handle boolean attributes | ||
| write(" %s=\"%s\"" % (qnames[k], v)) | ||
| if isinstance(v, QName): | ||
| v = qnames[v.text] | ||
| else: | ||
| v = _escape_attrib_html(v) | ||
| write(" %s=\"%s\"" % (k, v)) | ||
| write(">") | ||
| ltag = tag.lower() | ||
| if text: | ||
| if ltag == "script" or ltag == "style": | ||
| if ltag in _CDATA_CONTENT_ELEMENTS: | ||
| write(text) | ||
| else: | ||
| write(_escape_cdata(text)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Fix :mod:`~xml.etree.ElementTree` serialization to HTML. The content of | ||
| comments, processing instructions and elements "xmp", "iframe", "noembed", | ||
| "noframes", and "plaintext" is no longer escaped. The "plaintext" element no | ||
| longer have the closing tag. Add support of empty attributes (with value | ||
| ``None``). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'<spam> & ham','ham & eggs < spam','<spam>&ham')?