summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBo Bayles <bbayles@gmail.com>2018-01-26 00:02:03 (GMT)
committerÉric Araujo <merwok@netwok.org>2018-01-26 00:02:03 (GMT)
commit2fc98ae115e2a2095a0bcf388c27a878aafdb454 (patch)
treebed6c6b572eff1a289631ad1201573b086418781
parentc47dacb69054f6fe1c2465df585985430f7fe366 (diff)
downloadcpython-2fc98ae115e2a2095a0bcf388c27a878aafdb454.zip
cpython-2fc98ae115e2a2095a0bcf388c27a878aafdb454.tar.gz
cpython-2fc98ae115e2a2095a0bcf388c27a878aafdb454.tar.bz2
bpo-32304: Fix distutils upload for sdists ending with \x0d (GH-5264)
Patch by Bo Bayles.
-rw-r--r--Doc/whatsnew/3.7.rst5
-rw-r--r--Lib/distutils/command/upload.py2
-rw-r--r--Lib/distutils/tests/test_upload.py26
-rw-r--r--Misc/NEWS.d/next/Library/2018-01-21-16-33-53.bpo-32304.TItrNv.rst2
4 files changed, 33 insertions, 2 deletions
diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst
index e9f0570..0e1714e 100644
--- a/Doc/whatsnew/3.7.rst
+++ b/Doc/whatsnew/3.7.rst
@@ -416,6 +416,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`.)
+
http.client
-----------
diff --git a/Lib/distutils/command/upload.py b/Lib/distutils/command/upload.py
index 1fd574a..f7752f9 100644
--- a/Lib/distutils/command/upload.py
+++ b/Lib/distutils/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/Lib/distutils/tests/test_upload.py b/Lib/distutils/tests/test_upload.py
index 2cb2f6c..c17d8e7 100644
--- a/Lib/distutils/tests/test_upload.py
+++ b/Lib/distutils/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
diff --git a/Misc/NEWS.d/next/Library/2018-01-21-16-33-53.bpo-32304.TItrNv.rst b/Misc/NEWS.d/next/Library/2018-01-21-16-33-53.bpo-32304.TItrNv.rst
new file mode 100644
index 0000000..c199a64
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-01-21-16-33-53.bpo-32304.TItrNv.rst
@@ -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.