Skip to content

Commit f29286e

Browse files
committed
A fix for parsing parameters when there are semicolons inside the
quotes. Fixes SF bug #794466, with the essential patch provided by Stuart D. Gathman. Specifically, _parseparam(), _get_params_preserve(): Use the parsing function that takes quotes into account, as given (essentially) in the bug report's test program. Backport candidate.
1 parent 3b7340c commit f29286e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Lib/email/Message.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ def _formatparam(param, value=None, quote=True):
5858
else:
5959
return param
6060

61+
def _parseparam(s):
62+
plist = []
63+
while s[:1] == ';':
64+
s = s[1:]
65+
end = s.find(';')
66+
while end > 0 and s.count('"', 0, end) % 2:
67+
end = s.find(';', end + 1)
68+
if end < 0:
69+
end = len(s)
70+
f = s[:end]
71+
if '=' in f:
72+
i = f.index('=')
73+
f = f[:i].strip().lower() + '=' + f[i+1:].strip()
74+
plist.append(f.strip())
75+
s = s[end:]
76+
return plist
77+
6178

6279
def _unquotevalue(value):
6380
if isinstance(value, TupleType):
@@ -525,7 +542,7 @@ def _get_params_preserve(self, failobj, header):
525542
if value is missing:
526543
return failobj
527544
params = []
528-
for p in paramre.split(value):
545+
for p in _parseparam(';' + value):
529546
try:
530547
name, val = p.split('=', 1)
531548
name = name.strip()

0 commit comments

Comments
 (0)