email: UnboundLocalError parsing a Message-ID whose domain literal starts with whitespace
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 35/100
Línea de trabajo
Start in email._header_value_parser, at _get_ptext_to_endchars, and reproduce the issue with parse_message_id('<a@[ x]>'). Done means parsing returns a header with a defect instead of raising UnboundLocalError; the issue mentions linked PR gh-161967, so check its status before starting.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug report
email._header_value_parser.parse_message_id and parse_message_ids raise UnboundLocalError when the part after @ is a domain literal that starts with a space or tab, such as <a@[ x]>. Because of this, reading Message-ID, References or In-Reply-To from such a message with policy.default raises instead of returning a header with a defect. gh-134152 fixed the same error for an empty literal (<T@[), but a literal that begins with whitespace still reaches the same code.
import email
from email import policy
from email._header_value_parser import parse_message_id
parse_message_id('<a@[ x]>')
msg = email.message_from_string('Message-ID: <a@[ x]>\n\nbody\n', policy=policy.default)
msg['Message-ID']
Actual:
UnboundLocalError: cannot access local variable 'pos' where it is not associated with a value
Expected: no exception. The header should parse with a defect, the same way <a@[x ]> already does (it gives a MessageID with an ObsoleteHeaderDefect, "obsolete id-right in msg-id").
The cause is in _get_ptext_to_endchars: when value starts with whitespace, the first fragment from _wsp_splitter is empty, the for pos in ... loop never runs, and the else clause reads pos before it is assigned.
CPython versions tested on:
3.15, CPython main branch
Operating systems tested on:
Linux
Found while building a Lean 4 model of CPython (https://broyojo.com/python-formalization/). AI tools (Claude) helped investigate the findings and prepare this report. The examples were rerun on CPython 3.15.2 and main, and the report received technical review. Record: textlibs-email-msgid-no-fold-literal-space
Linked PRs
- gh-161967
- Lenguaje dominante
- Python
- Estrellas
- 78.2k
- Forks
- 36.6k
- Merge medio
- 19 h 57 min
- PR fusionados (30 d)
- 630
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de python/cpython
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
stdlib type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
extension-modules stdlib topic-XML type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
python/cpython#161807 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
stdlib type-feature
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
python/cpython#161788 · 7 comentarios ·
Los mantenedores suelen responder en 1 día
-
extension-modules topic-IO type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
Todos los issues de python/cpython
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
cpp-best-practices/project_validator#267 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Project-N-E-K-O/N.E.K.O#3725 ·
Los mantenedores suelen responder en 1 día
-
[Bug] Sending a Telegram message chain twice duplicates mentionsPosiblemente ocupada @123XieC la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
AstrBotDevs/AstrBot#11125 ·
Los mantenedores suelen responder en 1 día
-
backend bug priority: high
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
nooriegarg/ContribIQ#73 ·
Los mantenedores suelen responder en 1 día
-
bug p3 security
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
amd/gaia#8197 · 2 comentarios ·
Los mantenedores suelen responder en 1 día