summaryrefslogtreecommitdiffstats
path: root/Lib/email/Message.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2003-09-03 04:08:13 (GMT)
committerBarry Warsaw <barry@python.org>2003-09-03 04:08:13 (GMT)
commita74e868857e2122d3e5c895a86a8cf930af48e0a (patch)
tree9f140326705c061ee4bf3c0088f2314432619a2c /Lib/email/Message.py
parent6ec58ca9cfe53eb6f5ada8fe4ffe78c405d4b385 (diff)
downloadcpython-a74e868857e2122d3e5c895a86a8cf930af48e0a.zip
cpython-a74e868857e2122d3e5c895a86a8cf930af48e0a.tar.gz
cpython-a74e868857e2122d3e5c895a86a8cf930af48e0a.tar.bz2
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.
Diffstat (limited to 'Lib/email/Message.py')
-rw-r--r--Lib/email/Message.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/email/Message.py b/Lib/email/Message.py
index 6bba6ae..d4c10df 100644
--- a/Lib/email/Message.py
+++ b/Lib/email/Message.py
@@ -58,6 +58,23 @@ def _formatparam(param, value=None, quote=True):
else:
return param
+def _parseparam(s):
+ plist = []
+ while s[:1] == ';':
+ s = s[1:]
+ end = s.find(';')
+ while end > 0 and s.count('"', 0, end) % 2:
+ end = s.find(';', end + 1)
+ if end < 0:
+ end = len(s)
+ f = s[:end]
+ if '=' in f:
+ i = f.index('=')
+ f = f[:i].strip().lower() + '=' + f[i+1:].strip()
+ plist.append(f.strip())
+ s = s[end:]
+ return plist
+
def _unquotevalue(value):
if isinstance(value, TupleType):
@@ -525,7 +542,7 @@ class Message:
if value is missing:
return failobj
params = []
- for p in paramre.split(value):
+ for p in _parseparam(';' + value):
try:
name, val = p.split('=', 1)
name = name.strip()