]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[Bug #1472827] Correctly escape newlines and tabs in attribute values in saxutils...
authorAndrew M. Kuchling <amk@amk.ca>
Fri, 9 Jun 2006 14:00:15 +0000 (14:00 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Fri, 9 Jun 2006 14:00:15 +0000 (14:00 +0000)
Lib/test/test_sax.py
Lib/xml/sax/saxutils.py
Misc/NEWS

index 210ca196660d21cca4675ea9ec96b12313faa6f8..c2549ca678a997668b3dc871bb0560138234e9d4 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:
index de45cdd8255ee90b01a999643dcf0f430944581a..5230d9ac2f7b343a9bab4e92b2e684cb896effd4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -69,6 +69,10 @@ Library
   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
 -----------