diff --git a/addons/mail/models/mail_render_mixin.py b/addons/mail/models/mail_render_mixin.py
index 02e157674d130..27eec61461836 100644
--- a/addons/mail/models/mail_render_mixin.py
+++ b/addons/mail/models/mail_render_mixin.py
@@ -162,7 +162,14 @@ def _sub_relative2absolute(match):
_sub_relative2absolute.base_url = base_url
html = re.sub(r"""(
]*\ssrc=")(/[^/][^"]+)""", _sub_relative2absolute, html)
html = re.sub(r"""(]*\shref=")(/[^/][^"]+)""", _sub_relative2absolute, html)
- html = re.sub(r"""(<[^>]+\bstyle="[^"]+\burl\('?)(/[^/'][^'")]+)""", _sub_relative2absolute, html)
+ html = re.sub(re.compile(
+ r"""( # Group 1: element up to url in style
+ <[^>]+\bstyle=" # Element with a style attribute
+ [^"]+\burl\( # Style attribute contains "url(" style
+ (?:&\#34;|')?) # url style may start with (escaped) quote: capture it
+ ( # Group 2: url itself
+ /(?:[^'")]|(?!&\#34;))+ # stop at the first closing quote
+ )""", re.VERBOSE), _sub_relative2absolute, html)
return wrapper(html)
diff --git a/addons/mail/tests/test_mail_render.py b/addons/mail/tests/test_mail_render.py
index 9f97ff6d676d8..4d13d47ec9fe3 100644
--- a/addons/mail/tests/test_mail_render.py
+++ b/addons/mail/tests/test_mail_render.py
@@ -221,7 +221,7 @@ def test_render_template_local_links(self):
rendered_local_links = [
'' % base_url,
'' % base_url,
- ''
+ '' % base_url
]
for source, expected in zip(local_links_template_bits, rendered_local_links):
rendered = self.env['mail.render.mixin']._replace_local_links(source)