imaplib.Time2Internaldate raises IndexError instead of ValueError on an empty string
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece pelo ponto de entrada imaplib.Time2Internaldate e revise o caminho de string vazia relatado na issue. Verifique o teste de regressão e a entrada de NEWS mencionados na issue; está concluído quando uma entrada vazia gera ValueError, enquanto as outras entradas mantêm seu comportamento.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- networking
- Tipo de issue
- Bug
- Dificuldade
- 1/5
- Tempo estimado
- Menos de uma hora
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 20/100