This repository was archived by the owner on Feb 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -405,6 +405,14 @@ def test_attrib(self):
405
405
self .assertEqual (ET .tostring (elem ),
406
406
b'<test testa="testval" testb="test1" testc="test2">aa</test>' )
407
407
408
+ elem = ET .Element ('test' )
409
+ elem .set ('a' , '\r ' )
410
+ elem .set ('b' , '\r \n ' )
411
+ elem .set ('c' , '\t \n \r ' )
412
+ elem .set ('d' , '\n \n ' )
413
+ self .assertEqual (ET .tostring (elem ),
414
+ b'<test a=" " b=" " c="	 " d=" " />' )
415
+
408
416
def test_makeelement (self ):
409
417
# Test makeelement handling.
410
418
Original file line number Diff line number Diff line change @@ -1083,8 +1083,19 @@ def _escape_attrib(text):
1083
1083
text = text .replace (">" , ">" )
1084
1084
if "\" " in text :
1085
1085
text = text .replace ("\" " , """ )
1086
+ # The following business with carriage returns is to satisfy
1087
+ # Section 2.11 of the XML specification, stating that
1088
+ # CR or CR LN should be replaced with just LN
1089
+ # http://www.w3.org/TR/REC-xml/#sec-line-ends
1090
+ if "\r \n " in text :
1091
+ text = text .replace ("\r \n " , "\n " )
1092
+ if "\r " in text :
1093
+ text = text .replace ("\r " , "\n " )
1094
+ #The following four lines are issue 17582
1086
1095
if "\n " in text :
1087
1096
text = text .replace ("\n " , " " )
1097
+ if "\t " in text :
1098
+ text = text .replace ("\t " , "	" )
1088
1099
return text
1089
1100
except (TypeError , AttributeError ):
1090
1101
_raise_serialization_error (text )
Original file line number Diff line number Diff line change @@ -83,6 +83,9 @@ Library
83
83
84
84
- Issue #24594: Validates persist parameter when opening MSI database
85
85
86
+ - Issue #17582: xml.etree.ElementTree nows preserves whitespaces in attributes
87
+ (Patch by Duane Griffin. Reviewed and approved by Stefan Behnel.)
88
+
86
89
- Issue #28047: Fixed calculation of line length used for the base64 CTE
87
90
in the new email policies.
88
91
You can’t perform that action at this time.
0 commit comments