Skip to content

Commit 78cb96f

Browse files
authored
Merge pull request pallets#2238 from davidism/bugfix/latin1-filename
filename can be latin-1, not just ascii
2 parents e13eaee + 09b4910 commit 78cb96f

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

flask/helpers.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
484484
485485
.. _RFC 2231: https://tools.ietf.org/html/rfc2231#section-4
486486
487-
:param filename_or_fp: the filename of the file to send in `latin-1`.
487+
:param filename_or_fp: the filename of the file to send.
488488
This is relative to the :attr:`~Flask.root_path`
489489
if a relative path is specified.
490490
Alternatively a file object might be provided in
@@ -541,15 +541,12 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
541541
raise TypeError('filename unavailable, required for '
542542
'sending as attachment')
543543

544-
normalized = unicodedata.normalize(
545-
'NFKD', text_type(attachment_filename)
546-
)
547-
548544
try:
549-
normalized.encode('ascii')
545+
attachment_filename = attachment_filename.encode('latin-1')
550546
except UnicodeEncodeError:
551547
filenames = {
552-
'filename': normalized.encode('ascii', 'ignore'),
548+
'filename': unicodedata.normalize(
549+
'NFKD', attachment_filename).encode('latin-1', 'ignore'),
553550
'filename*': "UTF-8''%s" % url_quote(attachment_filename),
554551
}
555552
else:

0 commit comments

Comments
 (0)