[Python-checkins] r78125 - in python/trunk: Lib/test/test_xml_etree.py Lib/xml/etree/ElementTree.py Misc/ACKS Misc/NEWS

antoine.pitrou python-checkins at python.org
Tue Feb 9 18:08:06 CET 2010


Author: antoine.pitrou
Date: Tue Feb 9 18:08:05 2010
New Revision: 78125
Log:
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.
Modified:
 python/trunk/Lib/test/test_xml_etree.py
 python/trunk/Lib/xml/etree/ElementTree.py
 python/trunk/Misc/ACKS
 python/trunk/Misc/NEWS
Modified: python/trunk/Lib/test/test_xml_etree.py
==============================================================================
--- python/trunk/Lib/test/test_xml_etree.py	(original)
+++ python/trunk/Lib/test/test_xml_etree.py	Tue Feb 9 18:08:05 2010
@@ -213,6 +213,23 @@
 """
 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)
Modified: python/trunk/Lib/xml/etree/ElementTree.py
==============================================================================
--- python/trunk/Lib/xml/etree/ElementTree.py	(original)
+++ python/trunk/Lib/xml/etree/ElementTree.py	Tue Feb 9 18:08:05 2010
@@ -666,9 +666,9 @@
 # write XML to file
 tag = node.tag
 if tag is Comment:
- file.write("<!-- %s -->" % _escape_cdata(node.text, encoding))
+ file.write("<!-- %s -->" % _encode(node.text, encoding))
 elif tag is ProcessingInstruction:
- file.write("<?%s?>" % _escape_cdata(node.text, encoding))
+ file.write("<?%s?>" % _encode(node.text, encoding))
 else:
 items = node.items()
 xmlns_items = [] # new namespaces in this scope
Modified: python/trunk/Misc/ACKS
==============================================================================
--- python/trunk/Misc/ACKS	(original)
+++ python/trunk/Misc/ACKS	Tue Feb 9 18:08:05 2010
@@ -525,6 +525,7 @@
 Sjoerd Mullender
 Sape Mullender
 Michael Muller
+Neil Muller
 R. David Murray
 Piotr Meyer
 John Nagle
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Tue Feb 9 18:08:05 2010
@@ -78,6 +78,11 @@
 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 #7868: logging: added loggerClass attribute to Manager.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /