New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: 1.0-maintenance
from

Conversation

Projects
None yet
1 participant
@garenchan
Contributor

garenchan commented Oct 4, 2018

  1. If attachment filename is bytes type and contains non-ascii coded bytes,
    then the following ASCII encoding process will raise a UnicodeDecodeError exception.

  2. Since the following exception handling uses unicodedata for normalization, this also implies that the attachment filename is a unicode when encoding .

    flask/flask/helpers.py

    Lines 570 to 577 in 363205b

    try:
    attachment_filename = attachment_filename.encode('ascii')
    except UnicodeEncodeError:
    filenames = {
    'filename': unicodedata.normalize(
    'NFKD', attachment_filename).encode('ascii', 'ignore'),
    'filename*': "UTF-8''%s" % url_quote(attachment_filename),
    }

  3. Since UnicodeDecodeError exception was raised, we can see that an ASCII decoding process was also performed implicitly when encoding bytes string. So this solution won't introduce unnecessary overhead.

garenchan added some commits Oct 4, 2018

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.

@garenchan garenchan closed this Oct 4, 2018

@garenchan garenchan reopened this Oct 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment