#17369: Improve handling of broken RFC2231 values in get_filename.

This fixes a regression relative to python2.
This commit is contained in:
R David Murray 2014-02-07 15:02:19 -05:00
parent bd3a11ba34
commit 1e949890f6
3 changed files with 28 additions and 0 deletions

View file

@ -337,6 +337,10 @@ def collapse_rfc2231_value(value, errors='replace',
# object. We do not want bytes() normal utf-8 decoder, we want a straight
# interpretation of the string as character bytes.
charset, language, text = value
if charset is None:
# Issue 17369: if charset/lang is None, decode_rfc2231 couldn't parse
# the value, so use the fallback_charset.
charset = fallback_charset
rawbytes = bytes(text, 'raw-unicode-escape')
try:
return str(rawbytes, charset, errors)