From e31db5d50288d69bfbeeee7f377f06f600b3aa5a Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 17 Jan 2023 20:31:06 +0530 Subject: [PATCH] fix: handle `tel:` links in emails (#19635) --- frappe/tests/test_utils.py | 16 ++++++++++++++++ frappe/utils/data.py | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/frappe/tests/test_utils.py b/frappe/tests/test_utils.py index cd656db6cd..c6f7b8302f 100644 --- a/frappe/tests/test_utils.py +++ b/frappe/tests/test_utils.py @@ -49,6 +49,7 @@ from frappe.utils.data import ( cast, cstr, duration_to_seconds, + expand_relative_urls, get_datetime, get_first_day_of_week, get_time, @@ -920,6 +921,21 @@ class TestMiscUtils(FrappeTestCase): self.assertEqual(safe_json_loads("{ /}"), "{ /}") self.assertEqual(safe_json_loads("12"), 12) # this is a quirk + def test_url_expansion(self): + unchanged_links = [ + "My Phone)", + "My Email)", + "Data)", + ] + for link in unchanged_links: + self.assertEqual(link, expand_relative_urls(link)) + + site = get_url() + + transforms = [("About)", f"About)")] + for input, output in transforms: + self.assertEqual(output, expand_relative_urls(input)) + class TestTypingValidations(FrappeTestCase): ERR_REGEX = f"^Argument '.*' should be of type '.*' but got '.*' instead.$" diff --git a/frappe/utils/data.py b/frappe/utils/data.py index 921d112860..3e2d3c0959 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -1885,7 +1885,7 @@ def expand_relative_urls(html: str) -> str: def _expand_relative_urls(match): to_expand = list(match.groups()) - if not to_expand[2].startswith("mailto") and not to_expand[2].startswith("data:"): + if not to_expand[2].startswith(("mailto", "data:", "tel:")): if not to_expand[2].startswith("/"): to_expand[2] = "/" + to_expand[2] to_expand.insert(2, url)