From d9e5eff23d7c9190e3defd82a55a9372b547cb3b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 25 Nov 2018 17:27:31 -0600 Subject: [PATCH] Fix download filename when it contains spaces --- tailbone/views/master.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tailbone/views/master.py b/tailbone/views/master.py index 8d3af454..58b283ce 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -1467,12 +1467,13 @@ class MasterView(View): response.content_type = content_type else: response.content_type = six.binary_type(content_type) - if six.PY3: - filename = os.path.basename(path) - response.content_disposition = 'attachment; filename={}'.format(filename) - else: - filename = os.path.basename(path).encode('ascii', 'replace') - response.content_disposition = b'attachment; filename={}'.format(filename) + + # content-disposition + filename = os.path.basename(path) + if six.PY2: + filename = filename.encode('ascii', 'replace') + response.content_disposition = str('attachment; filename="{}"'.format(filename)) + return response def download_content_type(self, path, filename):