python / python/cpython

email: unquoted apostrophe in a MIME parameter value is dropped under policy.default

Aberta
#153,823 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

stdlib topic-email type-bug
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:

With policy.default a parameter value containing an unquoted apostrophe is not returned, while compat32 returns it. The apostrophe is not a tspecial (RFC 2045), so a bare value such as filename=O'Brien.pdf is a valid token and should be parsed whole.

import email, email.policy
msg = email.message_from_string(
    "Content-Disposition: attachment; filename=O'Brien.pdf\n\nbody\n", 
    policy=email.policy.default
)
msg.get_filename() is None
True

Under email.policy.compat32 the same string returns "O'Brien.pdf". Quoting the value (filename="O'Brien.pdf") works under both policies.

For a multipart message an unquoted apostrophe in the boundary is not recognized, so is_multipart() returns False and the message is not split.

ASPECIALS in Lib/email/_header_value_parser.py includes "'" unconditionally, which terminates the value.

Observed on 3.16.0a0.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs
  • gh-153842
  • gh-153846

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece em Lib/email/_header_value_parser.py, onde a issue identifica ASPECIALS como terminador do valor do parâmetro. Adicione cobertura de regressão para um apóstrofo não entre aspas em um nome de arquivo de Content-Disposition e em um boundary multipart, depois execute os testes relevantes do parser de email e confirme que ambos os casos funcionam com policy.default.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
backend
Tipo de issue
Bug
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Estagnada
Clareza
Claramente especificada
Facilidade para iniciantes
25/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.