Commit 99f69ee7 authored by Antoine Pitrou's avatar Antoine Pitrou

Merged revisions 78125 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78125 | antoine.pitrou | 2010-02-09 18:08:05 +0100 (mar., 09 févr. 2010) | 7 lines

  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.
........
parent c77dd32b
...@@ -210,6 +210,26 @@ def check_encoding(ET, encoding): ...@@ -210,6 +210,26 @@ 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():
r"""
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&>?>'
>>> ET.tostring(ET.PI('test', '<testing&>\xe3'), 'latin1')
b"<?xml version='1.0' encoding='latin1'?>\n<?test <testing&>\xe3?>"
"""
def check_issue6233(): def check_issue6233():
""" """
>>> from xml.etree import ElementTree as ET >>> from xml.etree import ElementTree as ET
......
...@@ -662,9 +662,9 @@ class ElementTree: ...@@ -662,9 +662,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(b"<!-- " + _encode_cdata(node.text, encoding) + b" -->") file.write(_encode("<!-- %s -->" % node.text, encoding))
elif tag is ProcessingInstruction: elif tag is ProcessingInstruction:
file.write(b"<?" + _encode_cdata(node.text, encoding) + b"?>") file.write(_encode("<?%s?>" % node.text, encoding))
else: else:
items = list(node.items()) items = list(node.items())
xmlns_items = [] # new namespaces in this scope xmlns_items = [] # new namespaces in this scope
......
...@@ -529,6 +529,7 @@ Pablo Mouzo ...@@ -529,6 +529,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
......
...@@ -242,6 +242,11 @@ C-API ...@@ -242,6 +242,11 @@ C-API
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 #6233: ElementTree failed converting unicode characters to XML - Issue #6233: ElementTree failed converting unicode characters to XML
entities when they could't be represented in the requested output entities when they could't be represented in the requested output
encoding. Patch by Jerry Chen. encoding. Patch by Jerry Chen.
......
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