Browse Source

Make sure the attachment filename is text type.

If attachment filename is bytes type and contains non-ascii coded bytes,
then the following ASCII encoding process will trigger
UnicodeDecodeError exception.

Fix issue #2933.
pull/2934/head
garenchan 6 years ago
parent
commit
bd616602be
  1. 3
      flask/helpers.py

3
flask/helpers.py

@ -568,6 +568,9 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
'sending as attachment')
try:
# Make sure the attachment filename is text type.
if not isinstance(attachment_filename, text_type):
attachment_filename = attachment_filename.decode('utf-8')
attachment_filename = attachment_filename.encode('ascii')
except UnicodeEncodeError:
filenames = {

Loading…
Cancel
Save