From bd616602befaa395186fe3c6d448d98b4bee8a85 Mon Sep 17 00:00:00 2001 From: garenchan <1412950785@qq.com> Date: Thu, 4 Oct 2018 20:42:24 +0800 Subject: [PATCH] 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. --- flask/helpers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flask/helpers.py b/flask/helpers.py index 7679a496..4d747ad6 100644 --- a/flask/helpers.py +++ b/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 = {