forked from orbit-oss/flask
filename can be latin-1, not just ascii
only normalize basic name when utf-8 header is needed ref #2223
This commit is contained in:
parent
e13eaeeaf2
commit
09b49104f3
1 changed files with 4 additions and 7 deletions
|
|
@ -484,7 +484,7 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
|
||||||
|
|
||||||
.. _RFC 2231: https://tools.ietf.org/html/rfc2231#section-4
|
.. _RFC 2231: https://tools.ietf.org/html/rfc2231#section-4
|
||||||
|
|
||||||
:param filename_or_fp: the filename of the file to send in `latin-1`.
|
:param filename_or_fp: the filename of the file to send.
|
||||||
This is relative to the :attr:`~Flask.root_path`
|
This is relative to the :attr:`~Flask.root_path`
|
||||||
if a relative path is specified.
|
if a relative path is specified.
|
||||||
Alternatively a file object might be provided in
|
Alternatively a file object might be provided in
|
||||||
|
|
@ -541,15 +541,12 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
|
||||||
raise TypeError('filename unavailable, required for '
|
raise TypeError('filename unavailable, required for '
|
||||||
'sending as attachment')
|
'sending as attachment')
|
||||||
|
|
||||||
normalized = unicodedata.normalize(
|
|
||||||
'NFKD', text_type(attachment_filename)
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
normalized.encode('ascii')
|
attachment_filename = attachment_filename.encode('latin-1')
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
filenames = {
|
filenames = {
|
||||||
'filename': normalized.encode('ascii', 'ignore'),
|
'filename': unicodedata.normalize(
|
||||||
|
'NFKD', attachment_filename).encode('latin-1', 'ignore'),
|
||||||
'filename*': "UTF-8''%s" % url_quote(attachment_filename),
|
'filename*': "UTF-8''%s" % url_quote(attachment_filename),
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue