From 1ed7e604bc4f398e6a17c56f4cae1fb7644d7713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Thu, 20 Jul 2023 04:20:13 +0200 Subject: [PATCH] urlize: "@a@b" isn't a valid e-mail, don't mailto:ise it This chases https://lists.sr.ht/~sircmpwn/sr.ht-dev/%3Clelaromu5mjgibe6jywrc2iwoikon2piwo2h34rcsyjhbyge5y%40fdtowru7pv5e%3E and thus https://101010.pl/@mcc@mastodon.social/110742090990556162 It's a common way to spell both "a user of some site" but also universal in the mastodon world. None of these are valid e-mail addresses (especially since urlize makes @eater@cijber.social into @eater@cijber.social which straight-up just isn't really a valid e-mail address anyway). --- CHANGES.rst | 1 + src/jinja2/utils.py | 1 + tests/test_utils.py | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index bbfad1356..b71fd0986 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 diff --git a/src/jinja2/utils.py b/src/jinja2/utils.py index 4b4720f6d..78eb5bdfe 100644 --- a/src/jinja2/utils.py +++ b/src/jinja2/utils.py @@ -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) ): diff --git a/tests/test_utils.py b/tests/test_utils.py index 7b58af144..11f76c2eb 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -141,6 +141,14 @@ def test_escape_urlize_target(self): "http://example.org" ) + def test_urlize_mail_mastodon(self): + fr = "nabijaczleweli@nabijaczleweli.xyz\n@eater@cijber.social\n" + to = ( + '' + "nabijaczleweli@nabijaczleweli.xyz\n@eater@cijber.social\n" + ) + assert urlize(fr) == to + class TestLoremIpsum: def test_lorem_ipsum_markup(self):