Opened 3 days ago

Closed 31 hours ago

#36012 closed Bug (fixed)

Urlize incorrectly handles punctuation in email addresses

Reported by: Mike Edmunds Owned by: Mike Edmunds
Component: Utilities Version: 5.1
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Several punctuation characters (%, &, +, !, etc.) can—and sometimes do—appear in the local part of an email address (before the @). The urlize template filter doesn't correctly encode them, which can result in broken mailto links.

Example (Django 5.1.4):

from django.template.defaultfilters import urlize
urlize("it%dept@example.org")
#   '<a href="mailto:it%dept@example.org">it%dept@example.org</a>'
# Expected:
#   '<a href="mailto:it%25dept@example.org">it%dept@example.org</a>'

Clicking the resulting mailto link might work as expected, or do nothing, or could launch a mail composer with a missing or incorrect email address, depending on the specific address, browser and email app. Sequences that could also be percent-encoded characters (like "%de" in the example) are especially prone to unpredictable results.

The mailto URI spec RFC 6068 requires percent encoding most punctuation in this situation (section 2, item 1; also see section 5, Encoding).

Proposed fix: apply urllib.parse.quote() to local where the mailto link is constructed in django.utils.html.Urlizer. (Although not strictly necessary, it wouldn't hurt to also quote domain there.)

Change History (5)

comment:1 by Sarah Boyce, 2 days ago

Triage Stage: UnreviewedAccepted

comment:2 by Sarah Boyce, 2 days ago

Needs tests: set

comment:3 by Mike Edmunds, 45 hours ago

Needs tests: unset

comment:4 by Sarah Boyce, 31 hours ago

Triage Stage: AcceptedReady for checkin

comment:5 by Sarah Boyce <42296566+sarahboyce@…>, 31 hours ago

Resolution: fixed
Status: assignedclosed

In 322e49b:

Fixed #36012 -- Made mailto punctuation percent-encoded in Urlizer.

Urlizer was not properly encoding email addresses containing punctuation
in generated mailto links. Per RFC 6068, fixed by percent encoding
(urllib.parse.quote) the local and domain address parts.

Note: See TracTickets for help on using tickets.
Back to Top