Skip to content

gh-100900: Quote non-ASCII display names containing specials in formataddr - #155881

Open
nikolauspschuetz wants to merge 1 commit into
python:mainfrom
nikolauspschuetz:gh-100900-formataddr-nonascii-specials
Open

gh-100900: Quote non-ASCII display names containing specials in formataddr#155881
nikolauspschuetz wants to merge 1 commit into
python:mainfrom
nikolauspschuetz:gh-100900-formataddr-nonascii-specials

Conversation

@nikolauspschuetz

@nikolauspschuetz nikolauspschuetz commented Aug 16, 2026

Copy link
Copy Markdown

formataddr quotes an ASCII display name that contains specials (e.g. a comma in a "Last, First" name), but the non-ASCII branch returned charset.header_encode(name) unquoted. When the charset is configured not to RFC 2047-encode the name (e.g. add_charset('utf-8', None)), header_encode is a no-op, so a comma in the name is emitted bare and the header parses back as two addresses through getaddresses.

Quote the non-ASCII name when it still contains specials, mirroring the ASCII branch — default-charset output is unchanged, since a real RFC 2047 encoded word never contains specials. Adds a regression test.

Thanks to @tonghuaroot for confirming and pinpointing this on the issue.

Fixes #100900

… formataddr

formataddr() quotes an ASCII display name that contains specials, but the
non-ASCII branch returned charset.header_encode(name) unquoted. When the
charset is configured not to RFC 2047-encode the name (e.g. after
add_charset('utf-8', None)), header_encode is a no-op, so specials such as a
comma were emitted bare and the header no longer round-tripped through
getaddresses(). Quote such a name the same way the ASCII branch does.
@nikolauspschuetz
nikolauspschuetz force-pushed the gh-100900-formataddr-nonascii-specials branch from 30ff05b to 67562c4 Compare August 16, 2026 03:56
@nikolauspschuetz
nikolauspschuetz marked this pull request as ready for review August 16, 2026 04:15
@nikolauspschuetz
nikolauspschuetz requested a review from a team as a code owner August 16, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

email.utils.formataddr incorrect handling of unicode names with comma

1 participant