Skip to content

Commit

Permalink
Apply UTM injection only to http(s) links
Browse files Browse the repository at this point in the history
Other URI schemes should not care much about UTM parameters, so can be excluded
  • Loading branch information
amureki committed Aug 19, 2024
1 parent e755d1f commit 90031c2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions emark/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

from emark import conf, utils

INLINE_LINK_RE = re.compile(r"\[[^\]]+\]\(([^)]+)\)")
INLINE_HTML_LINK_RE = re.compile(r"href=\"([^\"]+)\"")
INLINE_LINK_RE = re.compile(r"\[[^\]]+\]\((https?://[^)]+)\)")
INLINE_HTML_LINK_RE = re.compile(r'href="https?://([^"]+)"')
CLS_NAME_TO_CAMPAIGN_RE = re.compile(
r".+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)"
)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def test_get_preheader(self):
)
assert email_message.preheader == "Donuts events are back!"

def test_set_utm_attributes(self):
def test_inject_utm_params(self):
email_message = MarkdownEmailTestWithSubject(
language="en-US",
context={"donut_name": "HoneyNuts", "donut_type": "Honey"},
Expand All @@ -272,6 +272,7 @@ def test_set_utm_attributes(self):
"This is another link! <https://www.example.com/?utm_source=website&utm_medium=email&utm_campaign=MARKDOWN_EMAIL_TEST_WITH_SUBJECT&foo=bar>"
in email_message.body
)
assert "555-2368 <tel:5552368>" in email_message.body

def test_get_utm_campaign_name(self):
assert (
Expand Down
1 change: 1 addition & 0 deletions tests/testapp/templates/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ Vanilla lollipop biscuit cake marzipan jelly.

[This is a link!](https://www.example.com)
[This is another link!](https://www.example.com/?foo=bar)
[555-2368](tel:5552368)

<a href="https://www.example.com/html">An HTML Link</a>

0 comments on commit 90031c2

Please sign in to comment.