email: non-ASCII whitespace after a space is lost from address display names
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 42/100
Piste de recherche
The bug is in get_fws() in Lib/email/_header_value_parser.py, which uses value.lstrip() and so strips Unicode whitespace beyond SP and HTAB. The issue body already links PR gh-161679, though the linked-PR list is empty, so check that PR before starting. Done means display names such as '. \xa0b' survive a round trip through the email parser, with a regression test in Lib/test/test_email.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Bug description:
The email header parser silently drops Unicode whitespace other than SP and HTAB (for example U+00A0 NO-BREAK SPACE, U+2003 EM SPACE, U+3000 IDEOGRAPHIC SPACE) when it follows a space in an address display name. A message generated by the email package itself doesn't round-trip:
import email
from email import policy
from email.message import EmailMessage
from email.headerregistry import Address
m = EmailMessage()
m['To'] = Address('. \xa0b', 'u', 'example.com')
print(m['To']) # =?utf-8?q?=2E_=C2=A0?=b <[email protected]>
m2 = email.message_from_string(m.as_string(), policy=policy.default)
print(ascii(m2['To'].addresses[0].display_name)) # '. b', expected '. \xa0b'
Received mail is affected too: To: =?utf-8?q?x_=C2=A0b?= <[email protected]> gives the display name 'x b'.
The cause is get_fws() in Lib/email/_header_value_parser.py:
def get_fws(value):
"""FWS = 1*WSP
...
newvalue = value.lstrip()
str.lstrip() strips all Unicode whitespace, but FWS is only SP and HTAB (RFC 5322 §3.2.2: FWS = ([*WSP CRLF] 1*WSP) / obs-FWS; RFC 5234: WSP = SP / HTAB). The extra characters end up in a WhiteSpaceTerminal, whose value is always a single space, so they are lost.
I couldn't find a test or comment saying stripping all Unicode whitespace was intended.
CPython versions tested on:
3.13, CPython main branch
Operating systems tested on:
Windows
Linked PRs
- gh-161679
- Langage dominant
- Python
- Étoiles
- 78.2k
- Forks
- 36.6k
- Merge moyen
- 19 h 57 min
- PR mergées (30 j)
- 630
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de python/cpython
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
stdlib type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour
-
extension-modules stdlib topic-XML type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
python/cpython#161807 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
stdlib type-feature
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
python/cpython#161788 · 7 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
extension-modules topic-IO type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de python/cpython
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
cpp-best-practices/project_validator#267 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Project-N-E-K-O/N.E.K.O#3725 ·
Les mainteneurs répondent en général sous 1 jour
-
[Bug] Sending a Telegram message chain twice duplicates mentionsPeut-être pris @123XieC l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
AstrBotDevs/AstrBot#11125 ·
Les mainteneurs répondent en général sous 1 jour
-
backend bug priority: high
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
nooriegarg/ContribIQ#73 ·
Les mainteneurs répondent en général sous 1 jour
-
bug p3 security
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
amd/gaia#8197 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour