[New-bugs-announce] [issue47244] email.utils.formataddr does not respect double spaces

Alec Rosenbaum report at bugs.python.org
Wed Apr 6 13:45:12 EDT 2022


New submission from Alec Rosenbaum <alec at rosenbaum.io>:

It seems that `email.utils.formataddr` and `email.utils.parseaddr` are not directly inverse from each other, because `formataddr` does not respect double spaces within the "realname" section.

For example:
```
from email.utils import formataddr, parseaddr

identity = '"foo  bar" <foo at example.com>'

print(formataddr(parseaddr(identity)))
# 'foo  bar <foo at example.com>'

print(formataddr(parseaddr(formataddr(parseaddr(identity)))))
# 'foo bar <foo at example.com>'
```

The first round trip strips the quotes, and the second round trip strips the double space in the "realname" section.

The utility function only seems to check for special characters, but it should also check for double spaces.

----------
components: email
messages: 416891
nosy: AlecRosenbaum, barry, r.david.murray
priority: normal
severity: normal
status: open
title: email.utils.formataddr does not respect double spaces
type: behavior
versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue47244>
_______________________________________


More information about the New-bugs-announce mailing list