diff --git a/Lib/http/cookies.py b/Lib/http/cookies.py --- a/Lib/http/cookies.py +++ b/Lib/http/cookies.py @@ -576,6 +576,12 @@ class BaseCookie(dict): # Start looking for a cookie match = patt.match(str, i) if not match: + semicolon_index = str.find(';', i) + if semicolon_index != -1: + # Skip over invalid cookie + i = semicolon_index + 1 + morsel_seen = False + continue # No more cookies break diff --git a/Lib/test/test_http_cookies.py b/Lib/test/test_http_cookies.py --- a/Lib/test/test_http_cookies.py +++ b/Lib/test/test_http_cookies.py @@ -56,7 +56,16 @@ 'Set-Cookie: d=r', 'Set-Cookie: f=h' )) - } + }, + { + 'data': 'a=b; messages=["\"]; c=d;', + 'dict': {'a':'b', 'c':'d'}, + 'repr': "", + 'output': '\n'.join(( + 'Set-Cookie: a=b', + 'Set-Cookie: c=d', + )) + }, ] for case in cases: