summaryrefslogtreecommitdiffstats
path: root/Lib/xml
diff options
context:
space:
mode:
authormefistotelis <listom@gmail.com>2020-04-12 12:51:58 (GMT)
committerGitHub <noreply@github.com>2020-04-12 12:51:58 (GMT)
commit5fd8123dfdf6df0a9c29363c8327ccfa0c1d41ac (patch)
treee2e54c6f4857356fec8c334a5d12b01ae3ca7ebd /Lib/xml
parent8f87eefe7f0576c05c488874eb9601a7a87c7312 (diff)
downloadcpython-5fd8123dfdf6df0a9c29363c8327ccfa0c1d41ac.zip
cpython-5fd8123dfdf6df0a9c29363c8327ccfa0c1d41ac.tar.gz
cpython-5fd8123dfdf6df0a9c29363c8327ccfa0c1d41ac.tar.bz2
bpo-39011: Preserve line endings within ElementTree attributes (GH-18468)
* bpo-39011: Preserve line endings within attributes Line endings within attributes were previously normalized to "\n" in Py3.7/3.8. This patch removes that normalization, as line endings which were replaced by entity numbers should be preserved in original form.
Diffstat (limited to 'Lib/xml')
-rw-r--r--Lib/xml/etree/ElementTree.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index c8d898f..da2bcad 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -1057,15 +1057,15 @@ 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
+ # Although section 2.11 of the XML specification states that CR or
+ # CR LN should be replaced with just LN, it applies only to EOLNs
+ # which take part of organizing file into lines. Within attributes,
+ # we are replacing these with entity numbers, so they do not count.
# http://www.w3.org/TR/REC-xml/#sec-line-ends
- if "\r\n" in text:
- text = text.replace("\r\n", "\n")
+ # The current solution, contained in following six lines, was
+ # discussed in issue 17582 and 39011.
if "\r" in text:
- text = text.replace("\r", "\n")
- #The following four lines are issue 17582
+ text = text.replace("\r", "&#13;")
if "\n" in text:
text = text.replace("\n", "&#10;")
if "\t" in text: