Skip to content
Myr

Merge pull request #2934 from garenchan/bugfix-#2933

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix issue #2933: Make sure the attachment filename is text type.

authored by David Lord · committed by GitHub · parents 232e5c8, 40118e7 · Browse files · 3 files+10 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+10 added−1 removed

  • tests:+2 added−0 removed
  • other:+8 added−1 removed

3 files+10 added−1 removed

modified:flask/helpers.py+3 added
565 unmodified lines
566 if attachment_filename is None:567 raise TypeError('filename unavailable, required for '568 'sending as attachment')569570 if not isinstance(attachment_filename, text_type):571 attachment_filename = attachment_filename.decode('utf-8')572573 try:574 attachment_filename = attachment_filename.encode('ascii')575 except UnicodeEncodeError:576 filenames = {
475 unmodified lines
modified:tests/test_helpers.py+2 added
642 unmodified lines
643 ('index.html', 'index.html', False),644 (u'Ñandú/pingüino.txt', '"Nandu/pinguino.txt"',645 '%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt'),646 (u'Vögel.txt', 'Vogel.txt', 'V%C3%B6gel.txt'),647 # Native string not marked as Unicode on Python 2648 ('tést.txt', 'test.txt', 't%C3%A9st.txt'),649 ))650 def test_attachment_filename_encoding(self, filename, ascii, utf8):651 rv = flask.send_file('static/index.html', as_attachment=True, attachment_filename=filename)652 rv.close()
304 unmodified lines
modified:CHANGES.rst+5 added-1 removed
11 unmodified lines
12- :func:`send_file` encodes filenames as ASCII instead of Latin-113 (ISO-8859-1). This fixes compatibility with Gunicorn, which is14 stricter about header encodings than PEP 3333. (`#2766`_)15- Allow custom CLIs using ``FlaskGroup`` to set the debug flag without16 it always being overwritten based on environment variables. (`#2765`_)16 it always being overwritten based on environment variables.17 (`#2765`_)18- ``flask --version`` outputs Werkzeug's version and simplifies the19 Python version. (`#2825`_)20- :func:`send_file` handles an ``attachment_filename`` that is a21 native Python 2 string (bytes) with UTF-8 coded bytes. (`#2933`_)2223.. _#2766: https://github.com/pallets/flask/issues/276624.. _#2765: https://github.com/pallets/flask/pull/276525.. _#2825: https://github.com/pallets/flask/pull/282526.. _#2933: https://github.com/pallets/flask/issues/2933272829Version 1.0.230-------------
896 unmodified lines