Skip to content

Commit

Permalink
urlize: "@A@b" isn't a valid e-mail, don't mailto:ise it
Browse files Browse the repository at this point in the history
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
  <a href="mailto:@eater@cijber.social">@eater@cijber.social</a>
which straight-up just isn't really a valid e-mail address anyway).
  • Loading branch information
nabijaczleweli committed Jul 20, 2023
1 parent 2a2bfb7 commit eb80ff3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
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:``


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 = "nabijaczleweli@nabijaczleweli.xyz\n@eater@cijber.social\n"
to = (
'<a href="mailto:nabijaczleweli@nabijaczleweli.xyz">'
"nabijaczleweli@nabijaczleweli.xyz</a>\n@eater@cijber.social\n"
)
assert urlize(fr) == to


class TestLoremIpsum:
def test_lorem_ipsum_markup(self):
Expand Down

0 comments on commit eb80ff3

Please sign in to comment.