mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #17582: xml.etree.ElementTree nows preserves whitespaces in attributes
(Patch by Duane Griffin. Reviewed and approved by Stefan Behnel.)
This commit is contained in:
parent
4b73676c3d
commit
076366c2a5
3 changed files with 22 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue