Kaydet (Commit) 42fb6ab4 authored tarafından Antoine Pitrou's avatar Antoine Pitrou

Issue #2746: Don't escape ampersands and angle brackets ("&", "<", ">")

in XML processing instructions and comments.  These raw characters are
allowed by the XML specification, and are necessary when outputting e.g.
PHP code in a processing instruction.  Patch by Neil Muller.
üst 7b5aa463
...@@ -213,6 +213,23 @@ def check_encoding(ET, encoding): ...@@ -213,6 +213,23 @@ def check_encoding(ET, encoding):
""" """
ET.XML("<?xml version='1.0' encoding='%s'?><xml />" % encoding) ET.XML("<?xml version='1.0' encoding='%s'?><xml />" % encoding)
def processinginstruction():
"""
Test ProcessingInstruction directly
>>> from xml.etree import ElementTree as ET
>>> ET.tostring(ET.ProcessingInstruction('test', 'instruction'))
'<?test instruction?>'
>>> ET.tostring(ET.PI('test', 'instruction'))
'<?test instruction?>'
Issue #2746
>>> ET.tostring(ET.PI('test', '<testing&>'))
'<?test <testing&>?>'
"""
# #
# xinclude tests (samples from appendix C of the xinclude specification) # xinclude tests (samples from appendix C of the xinclude specification)
......
...@@ -666,9 +666,9 @@ class ElementTree: ...@@ -666,9 +666,9 @@ class ElementTree:
# write XML to file # write XML to file
tag = node.tag tag = node.tag
if tag is Comment: if tag is Comment:
file.write("<!-- %s -->" % _escape_cdata(node.text, encoding)) file.write("<!-- %s -->" % _encode(node.text, encoding))
elif tag is ProcessingInstruction: elif tag is ProcessingInstruction:
file.write("<?%s?>" % _escape_cdata(node.text, encoding)) file.write("<?%s?>" % _encode(node.text, encoding))
else: else:
items = node.items() items = node.items()
xmlns_items = [] # new namespaces in this scope xmlns_items = [] # new namespaces in this scope
......
...@@ -525,6 +525,7 @@ Pablo Mouzo ...@@ -525,6 +525,7 @@ Pablo Mouzo
Sjoerd Mullender Sjoerd Mullender
Sape Mullender Sape Mullender
Michael Muller Michael Muller
Neil Muller
R. David Murray R. David Murray
Piotr Meyer Piotr Meyer
John Nagle John Nagle
......
...@@ -78,6 +78,11 @@ Core and Builtins ...@@ -78,6 +78,11 @@ Core and Builtins
Library Library
------- -------
- Issue #2746: Don't escape ampersands and angle brackets ("&", "<", ">")
in XML processing instructions and comments. These raw characters are
allowed by the XML specification, and are necessary when outputting e.g.
PHP code in a processing instruction. Patch by Neil Muller.
- Issue #7869: logging: improved diagnostic for format-time errors. - Issue #7869: logging: improved diagnostic for format-time errors.
- Issue #7868: logging: added loggerClass attribute to Manager. - Issue #7868: logging: added loggerClass attribute to Manager.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment