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.
This commit is contained in:
garenchan 2018-10-04 20:42:24 +08:00 committed by David Lord
parent 232e5c81bc
commit 40118e785f
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
3 changed files with 10 additions and 1 deletions

View file

@ -644,6 +644,8 @@ class TestSendfile(object):
(u'Ñandúpingüino.txt', '"Nandu/pinguino.txt"',
'%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt'),
(u'Vögel.txt', 'Vogel.txt', 'V%C3%B6gel.txt'),
# Native string not marked as Unicode on Python 2
('tést.txt', 'test.txt', 't%C3%A9st.txt'),
))
def test_attachment_filename_encoding(self, filename, ascii, utf8):
rv = flask.send_file('static/index.html', as_attachment=True, attachment_filename=filename)