From 076366c2a52b1446eb684806f95e10c91366094a Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 11 Sep 2016 23:18:03 -0700 Subject: Issue #17582: xml.etree.ElementTree nows preserves whitespaces in attributes (Patch by Duane Griffin. Reviewed and approved by Stefan Behnel.) --- Lib/xml/etree/ElementTree.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Lib/xml') diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index 6d1b0ab864c..92821c57062 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) -- cgit v1.2.3-65-gdbad