Fix a behavioral change in build_email_address() on Python 3.

Review Request #11679 — Created June 25, 2021 and submitted

Information

Djblets
release-2.x

Reviewers

build_email_address() has always been a wrapper around Python's
formataddr(), which historically has taken a name and e-mail address
and built a resulting string in the form of name <email>. It handled
putting quotes around the name, if needed, and escaped certain
characters.

Python 3 extended the behavior to convert full names with Unicode values
into escaped =?=utf-8?...=?= strings. This is fine for formataddr(),
since it's there to create suitable header values, but it's not what we
wanted in this function.

This change rewrites build_email_address() to do its own e-mail
building. The logic is roughly the same as Python's implementation. The
meat of it is the usage of their regexes for escaping or quoting, which
we can still pull in fine.

Unit tests were added to check the results when using Unicode
characters, ensuring behavior remains consistent across Python versions.

Unit tests pass on Python 2 and 3.

Summary ID
Fix a behavioral change in build_email_address() on Python 3.
`build_email_address()` has always been a wrapper around Python's `formataddr()`, which historically has taken a name and e-mail address and built a resulting string in the form of `name <email>`. It handled putting quotes around the name, if needed, and escaped certain characters. Python 3 extended the behavior to convert full names with Unicode values into escaped `=?=utf-8?...=?=` strings. This is fine for `formataddr()`, since it's there to create suitable header values, but it's not what we wanted in this function. This change rewrites `build_email_address()` to do its own e-mail building. The logic is roughly the same as Python's implementation. The meat of it is the usage of their regexes for escaping or quoting, which we can still pull in fine. Unit tests were added to check the results when using Unicode characters, ensuring behavior remains consistent across Python versions.
d66b52b120852a186afcb2d3c1ec211cfd332cd3
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-2.x (4fd5aa1)
Loading...