diff options
author | Raymond Hettinger <python@rcn.com> | 2016-09-12 06:23:24 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2016-09-12 06:23:24 (GMT) |
commit | 11fa3ffcb11caf628435670b213f9bc2e3ba4f67 (patch) | |
tree | a147fd06c6803f5ea86d4c419a99183ea3bdd14c /Lib | |
parent | 3dad1a5b8296334c028e4ce90980d0a69558f8b8 (diff) | |
parent | 076366c2a52b1446eb684806f95e10c91366094a (diff) | |
download | cpython-11fa3ffcb11caf628435670b213f9bc2e3ba4f67.zip cpython-11fa3ffcb11caf628435670b213f9bc2e3ba4f67.tar.gz cpython-11fa3ffcb11caf628435670b213f9bc2e3ba4f67.tar.bz2 |
merge
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_xml_etree.py | 8 | ||||
-rw-r--r-- | Lib/xml/etree/ElementTree.py | 11 |
2 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 6e54628..054ec8f 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -409,6 +409,14 @@ class ElementTreeTest(unittest.TestCase): self.assertEqual(ET.tostring(elem), b'<test testa="testval" testb="test1" testc="test2">aa</test>') + elem = ET.Element('test') + elem.set('a', '\r') + elem.set('b', '\r\n') + elem.set('c', '\t\n\r ') + elem.set('d', '\n\n') + self.assertEqual(ET.tostring(elem), + b'<test a=" " b=" " c="	 " d=" " />') + def test_makeelement(self): # Test makeelement handling. diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index 4b0c661..7354056 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -1084,8 +1084,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) |