mirror of
https://github.com/python/cpython.git
synced 2025-07-30 14:44:10 +00:00
decode_rfc2231(): Be more robust against buggy RFC 2231 encodings.
Specifically, instead of raising a ValueError when there is a single tick in the parameter, simply return that the entire string unquoted, with None for both the charset and the language. Also, if there are more than 2 ticks in the parameter, interpret the first three parts as the standard RFC 2231 parts, then the rest of the parts as the encoded string. Test cases added. Original fewer-than-3-parts fix by Tokio Kikuchi. Resolves SF bug # 1218081. I will back port the fix and tests to Python 2.4 (email 3.0) and Python 2.3 (email 2.5). Also, bump the version number to email 4.0.1, removing the 'alpha' moniker.
This commit is contained in:
parent
a2f60a47b5
commit
18d2f39af7
3 changed files with 43 additions and 4 deletions
|
@ -45,6 +45,7 @@ COMMASPACE = ', '
|
|||
EMPTYSTRING = ''
|
||||
UEMPTYSTRING = u''
|
||||
CRLF = '\r\n'
|
||||
TICK = "'"
|
||||
|
||||
specialsre = re.compile(r'[][\\()<>@,:;".]')
|
||||
escapesre = re.compile(r'[][\\()"]')
|
||||
|
@ -231,10 +232,14 @@ def unquote(str):
|
|||
def decode_rfc2231(s):
|
||||
"""Decode string according to RFC 2231"""
|
||||
import urllib
|
||||
parts = s.split("'", 2)
|
||||
if len(parts) == 1:
|
||||
parts = s.split(TICK, 2)
|
||||
if len(parts) <= 2:
|
||||
return None, None, urllib.unquote(s)
|
||||
charset, language, s = parts
|
||||
if len(parts) > 3:
|
||||
charset, language = parts[:2]
|
||||
s = TICK.join(parts[2:])
|
||||
else:
|
||||
charset, language, s = parts
|
||||
return charset, language, urllib.unquote(s)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue