diff options
author | Raymond Hettinger <python@rcn.com> | 2016-09-11 23:18:03 -0700 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2016-09-11 23:18:03 -0700 |
commit | 7b0c499e3b81feb353d64615aeaa6e793f57a8ca (patch) | |
tree | fa9c92c681b39d31e528cb802f575b344d979179 /Lib/xml/etree | |
parent | d6ed09a44461b4918bd9024a332b945f7d5accc8 (diff) | |
download | cpython-7b0c499e3b81feb353d64615aeaa6e793f57a8ca.tar.gz |
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.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index 6d1b0ab864..92821c5706 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -1083,8 +1083,19 @@ def _escape_attrib(text): text = text.replace(">", ">") if "\"" in text: text = text.replace("\"", """) + # 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", " ") + if "\t" in text: + text = text.replace("\t", "	") return text except (TypeError, AttributeError): _raise_serialization_error(text) |