fix: handle tel: links in emails (#19635)
This commit is contained in:
parent
f9496ff7e5
commit
e31db5d502
2 changed files with 17 additions and 1 deletions
|
|
@ -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 = [
|
||||
"<a href='tel:12345432'>My Phone</a>)",
|
||||
"<a href='mailto:hello@example.com'>My Email</a>)",
|
||||
"<a href='data:hello@example.com'>Data</a>)",
|
||||
]
|
||||
for link in unchanged_links:
|
||||
self.assertEqual(link, expand_relative_urls(link))
|
||||
|
||||
site = get_url()
|
||||
|
||||
transforms = [("<a href='/about'>About</a>)", f"<a href='{site}/about'>About</a>)")]
|
||||
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.$"
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue