From 90031c23ccb48f24bbdff1bdd6a99c074d9ba880 Mon Sep 17 00:00:00 2001 From: Rust Saiargaliev Date: Thu, 15 Aug 2024 11:25:11 +0200 Subject: [PATCH] Apply UTM injection only to http(s) links Other URI schemes should not care much about UTM parameters, so can be excluded --- emark/message.py | 4 ++-- tests/test_message.py | 3 ++- tests/testapp/templates/template.md | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/emark/message.py b/emark/message.py index 3ca2329..86c285b 100644 --- a/emark/message.py +++ b/emark/message.py @@ -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])|$)" ) diff --git a/tests/test_message.py b/tests/test_message.py index 2a74add..51c1eb0 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -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"}, @@ -272,6 +272,7 @@ def test_set_utm_attributes(self): "This is another link! " in email_message.body ) + assert "555-2368 " in email_message.body def test_get_utm_campaign_name(self): assert ( diff --git a/tests/testapp/templates/template.md b/tests/testapp/templates/template.md index a931bec..c4968a1 100644 --- a/tests/testapp/templates/template.md +++ b/tests/testapp/templates/template.md @@ -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) An HTML Link