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

This commit is contained in:
R David Murray 2014-02-07 15:04:26 -05:00
commit c489e83432
3 changed files with 28 additions and 0 deletions

View file

@ -347,6 +347,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)