[New-bugs-announce] [issue42256] BaseCookie.__parse_string() doesn't work with expires= between cookies

Paulie Pena report at bugs.python.org
Tue Nov 3 14:17:21 EST 2020


New submission from Paulie Pena <paulie4 at gmail.com>:

Since `requests` creates a comma-separated list for any duplicated headers, this causes a problem when `expires=...` is between two `Set-Cookie` header values. `BaseCookie.__parse_string()` in https://github.com/python/cpython/blob/master/Lib/http/cookies.py, in that case, will just give up, since it thinks it was given an invalid cookie. The fix is to replace the comma at the end of each trailing `expires=...` with a semicolon. Inside `BaseCookie.__parse_string()`, before the `while` loop, all that should be needed is to add this:
```
str = re.sub('(=\w{3},\s[\w\d\s-]{9,11}\s[\d:]{8}\sGMT),', r'\1;', str)
```

----------
components: Library (Lib)
messages: 380294
nosy: paulie4
priority: normal
severity: normal
status: open
title: BaseCookie.__parse_string() doesn't work with expires= between cookies
type: behavior
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42256>
_______________________________________


More information about the New-bugs-announce mailing list