Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

urlize: "@a@b" isn't a valid e-mail, don't mailto:ise it #1870

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Unreleased
- Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.
:pr:`1793`
- Use ``flit_core`` instead of ``setuptools`` as build backend.
- Don't ``mailto:``-``urlize()`` addresses in the form ``@a@b``. :pr:`1870`


Version 3.1.3
Expand Down
1 change: 1 addition & 0 deletions src/jinja2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ def trim_url(x: str) -> str:
elif (
"@" in middle
and not middle.startswith("www.")
and not middle.startswith("@")
and ":" not in middle
and _email_re.match(middle)
):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ def test_escape_urlize_target(self):
"http://example.org</a>"
)

def test_urlize_mail_mastodon(self):
fr = "[email protected]\n@[email protected]\n"
to = (
'<a href="mailto:[email protected]">'
"[email protected]</a>\n@[email protected]\n"
)
assert urlize(fr) == to


class TestLoremIpsum:
def test_lorem_ipsum_markup(self):
Expand Down