Bug description
`BaseCookie.load()` parses the cookie string in two phases: parse then apply. The comment says it rejects the string if syntactically invalid. However, `_is_legal_key()` validation runs during the apply phase (inside `Morsel.set()`), not the parse phase. Cookies before an illegal key are applied to the jar before `CookieError` is raised.
```python
from http.cookies import SimpleCookie, CookieError
C = SimpleCookie()
try:
C.load("a=1; b,c=2; d=3")
except CookieError:
pass
print(len(C)) # 1, expected 0
```
Related to gh-84183 but distinct: that issue is about raise-vs-silent for different invalid inputs; this is about partial state when `CookieError` IS raised.
CPython versions tested on
3.13, 3.14, main
Operating systems tested on
macOS
Linked PRs
Bug description
`BaseCookie.load()` parses the cookie string in two phases: parse then apply. The comment says it rejects the string if syntactically invalid. However, `_is_legal_key()` validation runs during the apply phase (inside `Morsel.set()`), not the parse phase. Cookies before an illegal key are applied to the jar before `CookieError` is raised.
```python
from http.cookies import SimpleCookie, CookieError
C = SimpleCookie()
try:
C.load("a=1; b,c=2; d=3")
except CookieError:
pass
print(len(C)) # 1, expected 0
```
Related to gh-84183 but distinct: that issue is about raise-vs-silent for different invalid inputs; this is about partial state when `CookieError` IS raised.
CPython versions tested on
3.13, 3.14, main
Operating systems tested on
macOS
Linked PRs