Skip to content
Myr

Merge pull request #2019 from pallets/bugfix/sendfile-error

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Do not cause errors for unknown files for sendfile

authored by Armin Ronacher · committed by GitHub · parents 3bd12b3, 11f3a3f · Browse files · 3 files+5 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+5 added−11 removed

  • tests:+1 added−3 removed
  • other:+4 added−8 removed

3 files+5 added−11 removed

modified:docs/upgrading.rst+2 added-2 removed
52 unmodified lines
53misleading ``name`` attribute. Silently swallowing errors in such cases was not54a satisfying solution.5556Additionally the default of falling back to ``application/octet-stream`` has57been removed. If Flask can't guess one or the user didn't provide one, the58function fails.57been restricted. If Flask can't guess one or the user didn't provide one, the58function fails if no filename information was provided.5960.. _upgrading-to-011:6162Version 0.11
410 unmodified lines
modified:flask/helpers.py+2 added-6 removed
511 unmodified lines
512 filename = None513514 if mimetype is None:515 if attachment_filename is not None:516 mimetype = mimetypes.guess_type(attachment_filename)[0]516 mimetype = mimetypes.guess_type(attachment_filename)[0] \517 or 'application/octet-stream'518519 if mimetype is None:519 if attachment_filename is not None:520 raise ValueError(521 'Unable to infer MIME-type from filename {0!r}, please '522 'pass one explicitly.'.format(attachment_filename)523 )520 raise ValueError(521 'Unable to infer MIME-type because no filename is available. '522 'Please set either `attachment_filename`, pass a filepath to '523 '`filename_or_fp` or set your own MIME-type via `mimetype`.'
419 unmodified lines
modified:tests/test_helpers.py+1 added-3 removed
400 unmodified lines
401 assert 'Unable to infer MIME-type' in str(excinfo)402 assert 'no filename is available' in str(excinfo)403404 with app.test_request_context():405 with pytest.raises(ValueError) as excinfo:406 flask.send_file(StringIO("LOL"), attachment_filename='filename')405 flask.send_file(StringIO("LOL"), attachment_filename='filename')407 assert "Unable to infer MIME-type from filename 'filename'" in str(excinfo)406407 def test_send_file_object(self):408 app = flask.Flask(__name__)409
411 unmodified lines