summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBo Bayles <bbayles@gmail.com>2018-01-25 18:02:03 -0600
committerÉric Araujo <merwok@netwok.org>2018-01-25 19:02:03 -0500
commitb3168e5e01e79300b17c1791eed97c4733fa7a49 (patch)
tree93e5b1b01bc2be8be9e618439683f1afa748add0
parent9a97c496dcd05e6b3d418903a3728daa790e29cc (diff)
downloadpython-setuptools-git-b3168e5e01e79300b17c1791eed97c4733fa7a49.tar.gz
bpo-32304: Fix distutils upload for sdists ending with \x0d (GH-5264)
Patch by Bo Bayles.
-rw-r--r--command/upload.py2
-rw-r--r--tests/test_upload.py26
2 files changed, 26 insertions, 2 deletions
diff --git a/command/upload.py b/command/upload.py
index 1fd574a9..f7752f9d 100644
--- a/command/upload.py
+++ b/command/upload.py
@@ -159,8 +159,6 @@ class upload(PyPIRCCommand):
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()
diff --git a/tests/test_upload.py b/tests/test_upload.py
index 2cb2f6ce..c17d8e7d 100644
--- a/tests/test_upload.py
+++ b/tests/test_upload.py
@@ -143,6 +143,32 @@ class uploadTestCase(BasePyPIRCCommandTestCase):
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