summaryrefslogtreecommitdiff
path: root/Lib/xml/etree/ElementTree.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2016-09-12 10:48:55 +0200
committerChristian Heimes <christian@python.org>2016-09-12 10:48:55 +0200
commit4d9a72902dec55fe87f105324adc4239a13d966f (patch)
tree12336d19f4aa31e4ef9d2687883006395c474b5d /Lib/xml/etree/ElementTree.py
parent9017ec1ea0347c4bd901c329254590a9f86a69b8 (diff)
parent0d5048cb21e431c1a8221e15563837090946be81 (diff)
downloadcpython-git-4d9a72902dec55fe87f105324adc4239a13d966f.tar.gz
merge
Diffstat (limited to 'Lib/xml/etree/ElementTree.py')
-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 4b0c661e31..735405681f 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -1084,8 +1084,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)