Skip to content
Myr

Keep using only filename if it's valid ascii

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

authored by Antonio Larrosa · committed by Antonio Larrosa · parent bf023e7 · Browse files · 1 file+16 added−7 removed
This commit

State

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

Diff stats

1 file+16 added−7 removed

  • other:+16 added−7 removed

1 file+16 added−7 removed

modified:flask/helpers.py+16 added-7 removed
12 unmodified lines
13import sys14import pkgutil15import posixpath16import mimetypes17import unicodedata17from unicodedata import normalize18from time import time19from zlib import adler3220from threading import RLock21from werkzeug.routing import BuildError
512 unmodified lines
534 if as_attachment:535 if attachment_filename is None:536 raise TypeError('filename unavailable, required for '537 'sending as attachment')538 filename_dict = {539 'filename': (unicodedata.normalize('NFKD',540 text_type(attachment_filename)).encode('ascii',541 'ignore')),542 'filename*': "UTF-8''%s" % url_quote(attachment_filename)}538 normalized = normalize('NFKD', text_type(attachment_filename))539540 try:541 normalized.encode('ascii')542 except UnicodeEncodeError:543 filenames = {544 'filename': normalized.encode('ascii', 'ignore'),545 'filename*': "UTF-8''%s" % url_quote(attachment_filename),546 }547 else:548 filenames = {549 'filename': attachment_filename,550 }551552 headers.add('Content-Disposition', 'attachment',544 **filename_dict)553 **filenames)554555 if current_app.use_x_sendfile and filename:556 if file is not None:557 file.close()
418 unmodified lines