Skip to content

Commit 92ce20e

Browse files
r-m-ndavidism
authored andcommitted
Fix error in send_file helper (pallets#2003)
* Fix error in send_file (mimetype_filename is not defined) * fix formatting error message in send_file
1 parent 96b6345 commit 92ce20e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

flask/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,8 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
518518
if mimetype is None:
519519
if attachment_filename is not None:
520520
raise ValueError(
521-
'Unable to infer MIME-type from filename {!r}, please '
522-
'pass one explicitly.'.format(mimetype_filename)
521+
'Unable to infer MIME-type from filename {0!r}, please '
522+
'pass one explicitly.'.format(attachment_filename)
523523
)
524524
raise ValueError(
525525
'Unable to infer MIME-type because no filename is available. '

tests/test_helpers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,14 @@ def test_send_file_object_without_mimetype(self):
398398
with app.test_request_context():
399399
with pytest.raises(ValueError) as excinfo:
400400
flask.send_file(StringIO("LOL"))
401-
402401
assert 'Unable to infer MIME-type' in str(excinfo)
403402
assert 'no filename is available' in str(excinfo)
404403

404+
with app.test_request_context():
405+
with pytest.raises(ValueError) as excinfo:
406+
flask.send_file(StringIO("LOL"), attachment_filename='filename')
407+
assert "Unable to infer MIME-type from filename 'filename'" in str(excinfo)
408+
405409
def test_send_file_object(self):
406410
app = flask.Flask(__name__)
407411

0 commit comments

Comments
 (0)