[Python-checkins] bpo-32304: Fix distutils upload for tar files ending with b'\r' (GH-5264) (GH-5331)
Éric Araujo
webhook-mailer at python.org
Mon Jan 29 09:31:35 EST 2018
https://github.com/python/cpython/commit/f5a793522d539afc84ac7888c9ad189097c43a75
commit: f5a793522d539afc84ac7888c9ad189097c43a75
branch: 2.7
author: Bo Bayles <bbayles at gmail.com>
committer: Éric Araujo <merwok at netwok.org>
date: 2018-01-29T09:31:32-05:00
summary:
bpo-32304: Fix distutils upload for tar files ending with b'\r' (GH-5264) (GH-5331)
Patch by Bo Bayles.
files:
A Misc/NEWS.d/next/Library/2018-01-21-16-33-53.bpo-32304.TItrNv.rst
M Doc/whatsnew/2.7.rst
M Lib/distutils/command/upload.py
M Lib/distutils/tests/test_upload.py
diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst
index 1857aa4e8f32..53333ebf7c1a 100644
--- a/Doc/whatsnew/2.7.rst
+++ b/Doc/whatsnew/2.7.rst
@@ -1218,6 +1218,11 @@ changes, or look through the Subversion logs for all the details.
created some new files that should be included.
(Fixed by Tarek Ziadé; :issue:`8688`.)
+ 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`.)
+
* The :mod:`doctest` module's :const:`IGNORE_EXCEPTION_DETAIL` flag
will now ignore the name of the module containing the exception
being tested. (Patch by Lennart Regebro; :issue:`7490`.)
diff --git a/Lib/distutils/command/upload.py b/Lib/distutils/command/upload.py
index b773f47f7684..ea4b8a551a60 100644
--- a/Lib/distutils/command/upload.py
+++ b/Lib/distutils/command/upload.py
@@ -155,8 +155,6 @@ def upload_file(self, command, pyversion, filename):
body.write(fn)
body.write("\r\n\r\n")
body.write(value)
- if value and value[-1] == '\r':
- body.write('\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 3d4f30504e8d..d22575458753 100644
--- a/Lib/distutils/tests/test_upload.py
+++ b/Lib/distutils/tests/test_upload.py
@@ -128,6 +128,32 @@ def test_upload(self):
auth = self.last_open.req.headers['Authorization']
self.assertNotIn('\n', auth)
+ # 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.ensure_finalized()
+ cmd.run()
+
+ headers = dict(self.last_open.req.headers)
+ self.assertEqual(headers['Content-length'], '2170')
+ self.assertIn(b'long description\r', self.last_open.req.data)
+ self.assertNotIn(b'long description\r\n', 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 000000000000..c199a644ad40
--- /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.
More information about the Python-checkins
mailing list