Skip to content

gh-153677: Fix ValueError in http.cookiejar.http2time() for a strict-format fake month#153678

Open
tonghuaroot wants to merge 2 commits into
python:mainfrom
tonghuaroot:cookiejar-http2time-strict-month
Open

gh-153677: Fix ValueError in http.cookiejar.http2time() for a strict-format fake month#153678
tonghuaroot wants to merge 2 commits into
python:mainfrom
tonghuaroot:cookiejar-http2time-strict-month

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

http2time() documents that it returns None for an unrecognized date
format, but the STRICT_DATE_RE fast path raised a raw ValueError when
the month field matched the pattern but named a non-existent month (for
example Foo), because MONTHS_LOWER.index() was called unguarded. The
slower parser already returns None for the same input.

Guard the fast-path month lookup and fall through to the slower parser on
failure; valid months are unaffected. This restores the "returns None,
never raises" contract established by gh-60385 for a different code path.

…trict-format fake month

The STRICT_DATE_RE fast path in http2time() matched date strings whose
month field fit the pattern but named a non-existent month (for example
"Foo"), then called MONTHS_LOWER.index() which raised a raw ValueError.
The documented contract is to return None for unrecognized formats, and
the slower parser already does so. Guard the fast-path month lookup and
fall through to the slower parser on failure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant