Index: Lib/test/test_xml_etree.py
===================================================================
--- Lib/test/test_xml_etree.py (revision 73267)
+++ Lib/test/test_xml_etree.py (working copy)
@@ -209,8 +209,25 @@
>>> check_encoding(ET, "mac-roman")
"""
ET.XML("" % encoding)
+
+def processinginstruction():
+ """
+ Test ProcessingInstruction directly
+ >>> from xml.etree import ElementTree as ET
+ >>> ET.tostring(ET.ProcessingInstruction('test', 'instruction'))
+ ''
+ >>> ET.tostring(ET.PI('test', 'instruction'))
+ ''
+
+ Issue #2746
+
+ >>> ET.tostring(ET.PI('test', ''))
+ '?>'
+
+ """
+
#
# xinclude tests (samples from appendix C of the xinclude specification)
Index: Lib/xml/etree/ElementTree.py
===================================================================
--- Lib/xml/etree/ElementTree.py (revision 73267)
+++ Lib/xml/etree/ElementTree.py (working copy)
@@ -662,9 +662,9 @@
# write XML to file
tag = node.tag
if tag is Comment:
- file.write(_encode("" % _escape_cdata(node.text), encoding))
+ file.write(_encode("" % node.text, encoding))
elif tag is ProcessingInstruction:
- file.write(_encode("%s?>" % _escape_cdata(node.text), encoding))
+ file.write(_encode("%s?>" % node.text, encoding))
else:
items = list(node.items())
xmlns_items = [] # new namespaces in this scope