]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 78125 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Tue, 9 Feb 2010 17:25:47 +0000 (17:25 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Tue, 9 Feb 2010 17:25:47 +0000 (17:25 +0000)
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.
........

Lib/test/test_xml_etree.py
Lib/xml/etree/ElementTree.py
Misc/ACKS
Misc/NEWS

index a7ad48b2e8e3219d4390e34a592ded62e79c03aa..3df18961ba44d563106b51dba2b55f8334a51f37 100644 (file)
@@ -210,6 +210,26 @@ def check_encoding(ET, 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():
     """
     >>> from xml.etree import ElementTree as ET
index c47573e313637a38168a5c993963e2782db4b4be..2663b336e73747eaa7bf64de82d5dd29dfae6fc8 100644 (file)
@@ -662,9 +662,9 @@ class ElementTree:
         # write XML to file
         tag = node.tag
         if tag is Comment:
-            file.write(b"<!-- " + _encode_cdata(node.text, encoding) + b" -->")
+            file.write(_encode("<!-- %s -->" % node.text, encoding))
         elif tag is ProcessingInstruction:
-            file.write(b"<?" + _encode_cdata(node.text, encoding) + b"?>")
+            file.write(_encode("<?%s?>" % node.text, encoding))
         else:
             items = list(node.items())
             xmlns_items = [] # new namespaces in this scope
index b5dccde4fd379792f9765235d83c460e0eaee9e0..847d1d1208f80990db3495e2568151fa92afc6b2 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -529,6 +529,7 @@ Pablo Mouzo
 Sjoerd Mullender
 Sape Mullender
 Michael Muller
+Neil Muller
 R. David Murray
 Piotr Meyer
 John Nagle
index 9d2b7cf083611308f28185c3e910a77b9dac221f..e544868c226ed995cb9a6138cef38758ecdb9be5 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -242,6 +242,11 @@ C-API
 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
   entities when they could't be represented in the requested output
   encoding.  Patch by Jerry Chen.