Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-32304: Fix distutils upload for tar files ending with b'\r' #5264

Merged
merged 7 commits into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,11 @@ therefore included in source distributions.
and ``platforms`` fields are not specified as a list or a string.
(Contributed by Berker Peksag in :issue:`19610`.)

The ``upload`` command now longer tries to change CR end-of-line characters
to CRLF. This fixes a corruption issue with sdists that ended with a byte
equivalent to CR.
(Contributed by Bo Bayles in :issue:`32304`.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbayles I used the name found in your github profile, is that ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's fine. Thanks!


http.client
-----------

Expand Down
2 changes: 0 additions & 2 deletions Lib/distutils/command/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ def upload_file(self, command, pyversion, filename):
body.write(title.encode('utf-8'))
body.write(b"\r\n\r\n")
body.write(value)
if value and value[-1:] == b'\r':
body.write(b'\n') # write an extra newline (lurve Macs)
body.write(end_boundary)
body = body.getvalue()

Expand Down
26 changes: 26 additions & 0 deletions Lib/distutils/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,32 @@ def test_upload(self):
results = self.get_logs(INFO)
self.assertEqual(results[-1], 75 * '-' + '\nxyzzy\n' + 75 * '-')

# bpo-32304: archives whose last byte was b'\r' were corrupted due to
# normalization intended for Mac OS 9.
def test_upload_correct_cr(self):
# content that ends with \r should not be modified.
tmp = self.mkdtemp()
path = os.path.join(tmp, 'xxx')
self.write_file(path, content='yy\r')
command, pyversion, filename = 'xxx', '2.6', path
dist_files = [(command, pyversion, filename)]
self.write_file(self.rc, PYPIRC_LONG_PASSWORD)

# other fields that ended with \r used to be modified, now are
# preserved.
pkg_dir, dist = self.create_dist(
dist_files=dist_files,
description='long description\r'
)
cmd = upload(dist)
cmd.show_response = 1
cmd.ensure_finalized()
cmd.run()

headers = dict(self.last_open.req.headers)
self.assertEqual(headers['Content-length'], '2172')
self.assertIn(b'long description\r', self.last_open.req.data)

def test_upload_fails(self):
self.next_msg = "Not Found"
self.next_code = 404
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distutils' upload command no longer corrupts tar files ending with a CR byte,
and no longer tries to convert CR to CRLF in any of the upload text fields.