File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -409,6 +409,14 @@ def test_attrib(self):
409409 self .assertEqual (ET .tostring (elem ),
410410 b'<test testa="testval" testb="test1" testc="test2">aa</test>' )
411411
412+ elem = ET .Element ('test' )
413+ elem .set ('a' , '\r ' )
414+ elem .set ('b' , '\r \n ' )
415+ elem .set ('c' , '\t \n \r ' )
416+ elem .set ('d' , '\n \n ' )
417+ self .assertEqual (ET .tostring (elem ),
418+ b'<test a=" " b=" " c="	 " d=" " />' )
419+
412420 def test_makeelement (self ):
413421 # Test makeelement handling.
414422
Original file line number Diff line number Diff line change @@ -1084,8 +1084,19 @@ def _escape_attrib(text):
10841084 text = text .replace (">" , ">" )
10851085 if "\" " in text :
10861086 text = text .replace ("\" " , """ )
1087+ # The following business with carriage returns is to satisfy
1088+ # Section 2.11 of the XML specification, stating that
1089+ # CR or CR LN should be replaced with just LN
1090+ # http://www.w3.org/TR/REC-xml/#sec-line-ends
1091+ if "\r \n " in text :
1092+ text = text .replace ("\r \n " , "\n " )
1093+ if "\r " in text :
1094+ text = text .replace ("\r " , "\n " )
1095+ #The following four lines are issue 17582
10871096 if "\n " in text :
10881097 text = text .replace ("\n " , " " )
1098+ if "\t " in text :
1099+ text = text .replace ("\t " , "	" )
10891100 return text
10901101 except (TypeError , AttributeError ):
10911102 _raise_serialization_error (text )
Original file line number Diff line number Diff line change @@ -209,6 +209,9 @@ Library
209209
210210- Issue #24594: Validates persist parameter when opening MSI database
211211
212+ - Issue #17582: xml.etree.ElementTree nows preserves whitespaces in attributes
213+ (Patch by Duane Griffin. Reviewed and approved by Stefan Behnel.)
214+
212215- Issue #28047: Fixed calculation of line length used for the base64 CTE
213216 in the new email policies.
214217
You can’t perform that action at this time.
0 commit comments