Commit 91c64a05 authored by Andrew M. Kuchling's avatar Andrew M. Kuchling

[Bug #1472827] Make saxutils.XMLGenerator handle \r\n\t in attribute values by...

[Bug #1472827] Make saxutils.XMLGenerator handle \r\n\t in attribute values by escaping them properly.   2.4 bugfix candidate.
parent 7dbb1ff7
...@@ -175,11 +175,14 @@ def test_xmlgen_attr_escape(): ...@@ -175,11 +175,14 @@ def test_xmlgen_attr_escape():
gen.endElement("e") gen.endElement("e")
gen.startElement("e", {"a": "'\""}) gen.startElement("e", {"a": "'\""})
gen.endElement("e") gen.endElement("e")
gen.startElement("e", {"a": "\n\r\t"})
gen.endElement("e")
gen.endElement("doc") gen.endElement("doc")
gen.endDocument() gen.endDocument()
return result.getvalue() == start \ return result.getvalue() == start + ("<doc a='\"'><e a=\"'\"></e>"
+ "<doc a='\"'><e a=\"'\"></e><e a=\"'&quot;\"></e></doc>" "<e a=\"'&quot;\"></e>"
"<e a=\"&#10;&#13;&#9;\"></e></doc>")
def test_xmlgen_ignorable(): def test_xmlgen_ignorable():
result = StringIO() result = StringIO()
......
...@@ -68,6 +68,8 @@ def quoteattr(data, entities={}): ...@@ -68,6 +68,8 @@ def quoteattr(data, entities={}):
the optional entities parameter. The keys and values must all be the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value. 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) data = escape(data, entities)
if '"' in data: if '"' in data:
if "'" in data: if "'" in data:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment