Skip to content

Commit

Permalink
don't apply urlize to @a@b (#2062)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Dec 20, 2024
2 parents 106d61c + 0cd6948 commit 7a41ddb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Unreleased
- ``PackageLoader`` shows a clearer error message when the package does not
contain the templates directory. :issue:`1705`
- Improve annotations for methods returning copies. :pr:`1880`
- ``urlize`` does not add ``mailto:`` to values like `@a@b`. :pr:`1870`


Version 3.1.4
Expand Down
2 changes: 2 additions & 0 deletions src/jinja2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ def trim_url(x: str) -> str:
elif (
"@" in middle
and not middle.startswith("www.")
# ignore values like `@a@b`
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 @@ -142,6 +142,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

0 comments on commit 7a41ddb

Please sign in to comment.