summaryrefslogtreecommitdiffstats
path: root/Lib/xml/etree
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-09-12 06:18:03 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-09-12 06:18:03 (GMT)
commit076366c2a52b1446eb684806f95e10c91366094a (patch)
treecb8d617ff122ea64fb9c8a3d45a59faa4a53d826 /Lib/xml/etree
parent4b73676c3d260b37b91dedbc0b286c4e779350e4 (diff)
downloadcpython-076366c2a52b1446eb684806f95e10c91366094a.zip
cpython-076366c2a52b1446eb684806f95e10c91366094a.tar.gz
cpython-076366c2a52b1446eb684806f95e10c91366094a.tar.bz2
Issue #17582: xml.etree.ElementTree nows preserves whitespaces in attributes
(Patch by Duane Griffin. Reviewed and approved by Stefan Behnel.)
Diffstat (limited to 'Lib/xml/etree')
-rw-r--r--Lib/xml/etree/ElementTree.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index 6d1b0ab..92821c5 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -1083,8 +1083,19 @@ def _escape_attrib(text):
text = text.replace(">", "&gt;")
if "\"" in text:
text = text.replace("\"", "&quot;")
+ # The following business with carriage returns is to satisfy
+ # Section 2.11 of the XML specification, stating that
+ # CR or CR LN should be replaced with just LN
+ # http://www.w3.org/TR/REC-xml/#sec-line-ends
+ if "\r\n" in text:
+ text = text.replace("\r\n", "\n")
+ if "\r" in text:
+ text = text.replace("\r", "\n")
+ #The following four lines are issue 17582
if "\n" in text:
text = text.replace("\n", "&#10;")
+ if "\t" in text:
+ text = text.replace("\t", "&#09;")
return text
except (TypeError, AttributeError):
_raise_serialization_error(text)