@@ -128,6 +128,32 @@ def test_upload(self):
128128 auth = self .last_open .req .headers ['Authorization' ]
129129 self .assertNotIn ('\n ' , auth )
130130
131+ # bpo-32304: archives whose last byte was b'\r' were corrupted due to
132+ # normalization intended for Mac OS 9.
133+ def test_upload_correct_cr (self ):
134+ # content that ends with \r should not be modified.
135+ tmp = self .mkdtemp ()
136+ path = os .path .join (tmp , 'xxx' )
137+ self .write_file (path , content = 'yy\r ' )
138+ command , pyversion , filename = 'xxx' , '2.6' , path
139+ dist_files = [(command , pyversion , filename )]
140+ self .write_file (self .rc , PYPIRC_LONG_PASSWORD )
141+
142+ # other fields that ended with \r used to be modified, now are
143+ # preserved.
144+ pkg_dir , dist = self .create_dist (
145+ dist_files = dist_files ,
146+ description = 'long description\r '
147+ )
148+ cmd = upload (dist )
149+ cmd .ensure_finalized ()
150+ cmd .run ()
151+
152+ headers = dict (self .last_open .req .headers )
153+ self .assertEqual (headers ['Content-length' ], '2170' )
154+ self .assertIn (b'long description\r ' , self .last_open .req .data )
155+ self .assertNotIn (b'long description\r \n ' , self .last_open .req .data )
156+
131157 def test_upload_fails (self ):
132158 self .next_msg = "Not Found"
133159 self .next_code = 404
0 commit comments