From a30951ec28e23a5d1c9380c4bd5844f2290c1dc8 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sat, 10 Sep 2016 03:33:53 +0300 Subject: [PATCH 1/3] Do not error for unknown files if send_file sends an actual file --- flask/helpers.py | 3 ++- tests/test_helpers.py | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/flask/helpers.py b/flask/helpers.py index 56a91dd8..4034112e 100644 --- a/flask/helpers.py +++ b/flask/helpers.py @@ -513,7 +513,8 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False, if mimetype is None: if attachment_filename is not None: - mimetype = mimetypes.guess_type(attachment_filename)[0] + mimetype = mimetypes.guess_type(attachment_filename)[0] \ + or 'application/octet-stream' if mimetype is None: if attachment_filename is not None: diff --git a/tests/test_helpers.py b/tests/test_helpers.py index fc85625e..e1469007 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -402,9 +402,7 @@ class TestSendfile(object): assert 'no filename is available' in str(excinfo) with app.test_request_context(): - with pytest.raises(ValueError) as excinfo: - flask.send_file(StringIO("LOL"), attachment_filename='filename') - assert "Unable to infer MIME-type from filename 'filename'" in str(excinfo) + flask.send_file(StringIO("LOL"), attachment_filename='filename') def test_send_file_object(self): app = flask.Flask(__name__) From 1f0ca894a27f12131079c27eccdcc3fc9283eadd Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 11 Sep 2016 16:57:43 +0300 Subject: [PATCH 2/3] Killed now dead code --- flask/helpers.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/flask/helpers.py b/flask/helpers.py index 4034112e..05361626 100644 --- a/flask/helpers.py +++ b/flask/helpers.py @@ -517,11 +517,6 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False, or 'application/octet-stream' if mimetype is None: - if attachment_filename is not None: - raise ValueError( - 'Unable to infer MIME-type from filename {0!r}, please ' - 'pass one explicitly.'.format(attachment_filename) - ) raise ValueError( 'Unable to infer MIME-type because no filename is available. ' 'Please set either `attachment_filename`, pass a filepath to ' From 11f3a3f6ddd5c6bc2b6223eb2ad7cf25e0010132 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 11 Sep 2016 21:28:30 +0300 Subject: [PATCH 3/3] Updated upgrade docs --- docs/upgrading.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/upgrading.rst b/docs/upgrading.rst index 6b933c59..41b70f03 100644 --- a/docs/upgrading.rst +++ b/docs/upgrading.rst @@ -54,8 +54,8 @@ misleading ``name`` attribute. Silently swallowing errors in such cases was not a satisfying solution. Additionally the default of falling back to ``application/octet-stream`` has -been removed. If Flask can't guess one or the user didn't provide one, the -function fails. +been restricted. If Flask can't guess one or the user didn't provide one, the +function fails if no filename information was provided. .. _upgrading-to-011: