[Python-checkins] r46777 - in python/branches/release24-maint: Lib/test/test_sax.py Lib/xml/sax/saxutils.py Misc/NEWS

andrew.kuchling python-checkins at python.org
Fri Jun 9 16:00:16 CEST 2006


Author: andrew.kuchling
Date: Fri Jun  9 16:00:15 2006
New Revision: 46777

Modified:
   python/branches/release24-maint/Lib/test/test_sax.py
   python/branches/release24-maint/Lib/xml/sax/saxutils.py
   python/branches/release24-maint/Misc/NEWS
Log:
[Bug #1472827] Correctly escape newlines and tabs in attribute values in saxutils.XMLGenerator

Modified: python/branches/release24-maint/Lib/test/test_sax.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_sax.py	(original)
+++ python/branches/release24-maint/Lib/test/test_sax.py	Fri Jun  9 16:00:15 2006
@@ -175,11 +175,14 @@
     gen.endElement("e")
     gen.startElement("e", {"a": "'\""})
     gen.endElement("e")
+    gen.startElement("e", {"a": "\n\r\t"})
+    gen.endElement("e")
     gen.endElement("doc")
     gen.endDocument()
 
-    return result.getvalue() == start \
-           + "<doc a='\"'><e a=\"'\"></e><e a=\"'&quot;\"></e></doc>"
+    return result.getvalue() == start + ("<doc a='\"'><e a=\"'\"></e>"
+                                         "<e a=\"'&quot;\"></e>"
+                                         "<e a=\"&#10;&#13;&#9;\"></e></doc>")
 
 def test_xmlgen_ignorable():
     result = StringIO()

Modified: python/branches/release24-maint/Lib/xml/sax/saxutils.py
==============================================================================
--- python/branches/release24-maint/Lib/xml/sax/saxutils.py	(original)
+++ python/branches/release24-maint/Lib/xml/sax/saxutils.py	Fri Jun  9 16:00:15 2006
@@ -68,6 +68,8 @@
     the optional entities parameter.  The keys and values must all be
     strings; each key will be replaced with its corresponding value.
     """
+    entities = entities.copy()
+    entities.update({'\n': '&#10;', '\r': '&#13;', '\t':'&#9;'})
     data = escape(data, entities)
     if '"' in data:
         if "'" in data:

Modified: python/branches/release24-maint/Misc/NEWS
==============================================================================
--- python/branches/release24-maint/Misc/NEWS	(original)
+++ python/branches/release24-maint/Misc/NEWS	Fri Jun  9 16:00:15 2006
@@ -69,6 +69,10 @@
   raise an exception some day.  But dicts have been allowed, and "mostly
   worked", so support for them won't go away without warning.
 
+- Bug #1472827: correctly escape newlines and tabs in attribute values in
+  the saxutils.XMLGenerator class.
+
+
 Tools/Demos
 -----------
 


More information about the Python-checkins mailing list