You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
imaplib.Time2Internaldate raises IndexError instead of ValueError on an empty string #153854
imaplib.Time2Internaldate is documented to raise ValueError for input that is not of a known type, and its own final branch is raise ValueError("date_time not of a known type"). However, the string branch subscripts the value before that check:
elifisinstance(date_time, str) and (date_time[0],date_time[-1]) == ('"','"'):
so an empty string escapes as a bare IndexError instead:
The fix is to use slices so the comparison is simply false for an empty string and control falls through to the intended ValueError:
elifisinstance(date_time, str) and (date_time[:1], date_time[-1:]) == ('"', '"'):
Behavior for all other inputs is unchanged. Related: gh-86165 recently fixed a different crash in this same function. I have a PR ready with the fix, a regression test, and a NEWS entry.
Activity
pythongh-153854: Fix imaplib.Time2Internaldate crash on an empty string
pythongh-153854: Add regression test for Time2Internaldate('')
Merge branch 'main' into fix-pythongh-153854-imaplib-time2internaldate
Merge branch 'main' into fix-pythongh-153854-imaplib-time2internaldate
Merge branch 'main' into fix-pythongh-153854-imaplib-time2internaldate
pythongh-153854: Raise ValueError from imaplib.Time2Internaldate on e…
Merge branch 'main' into fix-pythongh-153854-imaplib-time2internaldate
Merge branch 'main' into fix-pythongh-153854-imaplib-time2internaldate
Merge branch 'main' into fix-pythongh-153854-imaplib-time2internaldate
Merge branch 'main' into fix-pythongh-153854-imaplib-time2internaldate
pythongh-153854: Raise ValueError from imaplib.Time2Internaldate on e…
pythongh-153854: Add NEWS entry
Merge branch 'main' into fix-pythongh-153854-imaplib-time2internaldate
Merge branch 'main' into fix-pythongh-153854-imaplib-time2internaldate
Merge branch 'main' into fix-pythongh-153854-imaplib-time2internaldate
Merge branch 'main' into fix-pythongh-153854-imaplib-time2internaldate
Merge branch 'main' into fix-pythongh-153854-imaplib-time2internaldate
Merge branch 'main' into fix-pythongh-153854-imaplib-time2internaldate