Browse Source

Do not error for unknown files if send_file sends an actual file

reviewable/pr2019/r1
Armin Ronacher 8 years ago
parent
commit
a30951ec28
  1. 3
      flask/helpers.py
  2. 4
      tests/test_helpers.py

3
flask/helpers.py

@ -513,7 +513,8 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
if mimetype is None: if mimetype is None:
if attachment_filename is not 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 mimetype is None:
if attachment_filename is not None: if attachment_filename is not None:

4
tests/test_helpers.py

@ -402,9 +402,7 @@ class TestSendfile(object):
assert 'no filename is available' in str(excinfo) assert 'no filename is available' in str(excinfo)
with app.test_request_context(): with app.test_request_context():
with pytest.raises(ValueError) as excinfo: flask.send_file(StringIO("LOL"), attachment_filename='filename')
flask.send_file(StringIO("LOL"), attachment_filename='filename')
assert "Unable to infer MIME-type from filename 'filename'" in str(excinfo)
def test_send_file_object(self): def test_send_file_object(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)

Loading…
Cancel
Save