python / python/cpython

imaplib.Time2Internaldate raises IndexError instead of ValueError on an empty string

Abierto
#153,854 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

stdlib topic-email type-bug
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza en el punto de entrada imaplib.Time2Internaldate y revisa la ruta de cadena vacía indicada en el issue. Comprueba la prueba de regresión y la entrada de NEWS mencionadas en el issue; se considera terminado cuando una entrada vacía genera ValueError mientras las demás entradas conservan su comportamiento.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
networking
Tipo de issue
Error
Dificultad
1/5
Tiempo estimado
Menos de una hora
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
20/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.