http.cookies.BaseCookie.load() applies partial state before raising CookieError
未關閉
還沒有人認領這個 Issue。
stdlib
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
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.
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
- gh-154674
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 http.cookies.BaseCookie.load() 開始,使用報告中顯示的 cookie 字串重現該問題。確認 CookieError 會讓 cookie jar 保持為空;issue 內文連結到 PR gh-154674,因此請先檢查這項工作再繼續。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- networking
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100