diff -r 325aec842e3e Lib/cookielib.py --- a/Lib/cookielib.py Wed Feb 25 10:12:26 2015 -0500 +++ b/Lib/cookielib.py Fri Feb 27 08:26:46 2015 -0800 @@ -466,7 +466,13 @@ version_set = False for ii, param in enumerate(re.split(r";\s*", ns_header)): param = param.rstrip() - if param == "": continue + if param == "": + # RFC 6265, Section 5.2: + # If the name string is empty, ignore the set-cookie-string + # entirely. (The 0th element is the name string) + if ii == 0: + break + continue if "=" not in param: k, v = param, None else: diff -r 325aec842e3e Lib/test/test_cookielib.py --- a/Lib/test/test_cookielib.py Wed Feb 25 10:12:26 2015 -0500 +++ b/Lib/test/test_cookielib.py Fri Feb 27 08:26:46 2015 -0800 @@ -1106,6 +1106,8 @@ c.extract_cookies(r, req) return c + future = cookielib.time2netscape(time.time()+3600) + # none of these bad headers should cause an exception to be raised for headers in [ ["Set-Cookie: "], # actually, nothing wrong with this @@ -1116,6 +1118,8 @@ ["Set-Cookie: b=foo; max-age=oops"], # bad version ["Set-Cookie: b=foo; version=spam"], + # missing name (issue 23138) + ["Set-Cookie:; Expires=%s" % future], ]: c = cookiejar_from_cookie_headers(headers) # these bad cookies shouldn't be set