Skip to content

Commit 2fc98ae

Browse files
bbaylesmerwok
authored andcommitted
bpo-32304: Fix distutils upload for sdists ending with \x0d (GH-5264)
Patch by Bo Bayles.
1 parent c47dacb commit 2fc98ae

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

Doc/whatsnew/3.7.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ therefore included in source distributions.
416416
and ``platforms`` fields are not specified as a list or a string.
417417
(Contributed by Berker Peksag in :issue:`19610`.)
418418

419+
The ``upload`` command now longer tries to change CR end-of-line characters
420+
to CRLF. This fixes a corruption issue with sdists that ended with a byte
421+
equivalent to CR.
422+
(Contributed by Bo Bayles in :issue:`32304`.)
423+
419424
http.client
420425
-----------
421426

Lib/distutils/command/upload.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ def upload_file(self, command, pyversion, filename):
159159
body.write(title.encode('utf-8'))
160160
body.write(b"\r\n\r\n")
161161
body.write(value)
162-
if value and value[-1:] == b'\r':
163-
body.write(b'\n') # write an extra newline (lurve Macs)
164162
body.write(end_boundary)
165163
body = body.getvalue()
166164

Lib/distutils/tests/test_upload.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,32 @@ def test_upload(self):
143143
results = self.get_logs(INFO)
144144
self.assertEqual(results[-1], 75 * '-' + '\nxyzzy\n' + 75 * '-')
145145

146+
# bpo-32304: archives whose last byte was b'\r' were corrupted due to
147+
# normalization intended for Mac OS 9.
148+
def test_upload_correct_cr(self):
149+
# content that ends with \r should not be modified.
150+
tmp = self.mkdtemp()
151+
path = os.path.join(tmp, 'xxx')
152+
self.write_file(path, content='yy\r')
153+
command, pyversion, filename = 'xxx', '2.6', path
154+
dist_files = [(command, pyversion, filename)]
155+
self.write_file(self.rc, PYPIRC_LONG_PASSWORD)
156+
157+
# other fields that ended with \r used to be modified, now are
158+
# preserved.
159+
pkg_dir, dist = self.create_dist(
160+
dist_files=dist_files,
161+
description='long description\r'
162+
)
163+
cmd = upload(dist)
164+
cmd.show_response = 1
165+
cmd.ensure_finalized()
166+
cmd.run()
167+
168+
headers = dict(self.last_open.req.headers)
169+
self.assertEqual(headers['Content-length'], '2172')
170+
self.assertIn(b'long description\r', self.last_open.req.data)
171+
146172
def test_upload_fails(self):
147173
self.next_msg = "Not Found"
148174
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)