imaplib.Time2Internaldate raises IndexError instead of ValueError on an empty string
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug report
Bug description:
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:
elif isinstance(date_time, str) and (date_time[0],date_time[-1]) == ('"','"'):
so an empty string escapes as a bare IndexError instead:
>>> import imaplib
>>> imaplib.Time2Internaldate('')
Traceback (most recent call last):
...
IndexError: string index out of range
>>> imaplib.Time2Internaldate('x') # non-empty unquoted string is fine
Traceback (most recent call last):
...
ValueError: date_time not of a known type
The fix is to use slices so the comparison is simply false for an empty string and control falls through to the intended ValueError:
elif isinstance(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.
CPython versions tested on:
3.12, CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-153874
- gh-153929
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dal punto di ingresso imaplib.Time2Internaldate ed esamina il percorso della stringa vuota segnalato nell’issue. Controlla il test di regressione e la voce NEWS menzionati nell’issue; il lavoro è completato quando un input vuoto solleva ValueError, mentre gli altri input mantengono il loro comportamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- networking
- Tipo di issue
- Bug
- Difficoltà
- 1/5
- Tempo stimato
- Meno di un'ora
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 20/100