]> granicus.if.org Git - python/commitdiff
[Bug #1472827] Make saxutils.XMLGenerator handle \r\n\t in attribute values by escapi...
authorAndrew M. Kuchling <amk@amk.ca>
Fri, 9 Jun 2006 13:15:57 +0000 (13:15 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Fri, 9 Jun 2006 13:15:57 +0000 (13:15 +0000)
Lib/test/test_sax.py
Lib/xmlcore/sax/saxutils.py

index ded81fb2b5718e8cdc308250ab1d708f69ba1789..246d214d6addcfcd1ebe06e8142e34ac40fe1e91 100644 (file)
@@ -175,11 +175,14 @@ def test_xmlgen_attr_escape():
     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()
index 582b0089c4bf6d98e636198d085f21ef3ba9d709..a4965192fa833a75cdcbdce45f82d1842d52378c 100644 (file)
@@ -68,6 +68,8 @@ def quoteattr(data, entities={}):
     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: