Skip to content

Commit d365901

Browse files
authored
Use basename for file in content-disposition (#4713)
1 parent c516cc8 commit d365901

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/sentry/api/endpoints/release_file_details.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import absolute_import
2+
import posixpath
23

34
from rest_framework import serializers
45
from rest_framework.response import Response
@@ -79,7 +80,7 @@ def download(self, releasefile):
7980
content_type=file.headers.get('content-type', 'application/octet-stream'),
8081
)
8182
response['Content-Length'] = file.size
82-
response['Content-Disposition'] = "attachment; filename=%s" % releasefile.name
83+
response['Content-Disposition'] = 'attachment; filename="%s"' % posixpath.basename(releasefile.name)
8384
return response
8485

8586
@attach_scenarios([retrieve_file_scenario])

tests/sentry/api/endpoints/test_release_file_details.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_file_download(self):
8080

8181
response = self.client.get(url + '?download=1')
8282
assert response.status_code == 200, response.content
83-
assert response.get('Content-Disposition') == "attachment; filename=http://example.com/application.js"
83+
assert response.get('Content-Disposition') == 'attachment; filename="application.js"'
8484
assert response.get('Content-Length') == six.text_type(f.size)
8585
assert response.get('Content-Type') == 'application/octet-stream'
8686
assert 'File contents here' == BytesIO(b"".join(response.streaming_content)).getvalue()

0 commit comments

Comments
 (0)