Skip to content

Commit 85bb01b

Browse files
committed
[2.7] bpo-32304: Fix distutils upload for sdists ending with \x0d (pythonGH-5264)
Patch by Bo Bayles.. (cherry picked from commit 2fc98ae)
1 parent 6996f28 commit 85bb01b

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

Lib/distutils/command/upload.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ def upload_file(self, command, pyversion, filename):
155155
body.write(fn)
156156
body.write("\r\n\r\n")
157157
body.write(value)
158-
if value and value[-1] == '\r':
159-
body.write('\n') # write an extra newline (lurve Macs)
160158
body.write(end_boundary)
161159
body = body.getvalue()
162160

Lib/distutils/tests/test_upload.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.show_response = 1
150+
cmd.ensure_finalized()
151+
cmd.run()
152+
153+
headers = dict(self.last_open.req.headers)
154+
self.assertEqual(headers['Content-length'], '2172')
155+
self.assertIn(b'long description\r', self.last_open.req.data)
156+
131157
def test_upload_fails(self):
132158
self.next_msg = "Not Found"
133159
self.next_code = 404
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distutils' upload command no longer corrupts tar files ending with a CR byte,
2+
and no longer tries to convert CR to CRLF in any of the upload text fields.

0 commit comments

Comments
 (0)