[FIX] base: avoid to escape image when src contains @
The content id of an attachement can contains a @, therefore image contained in emails where sometimes escaped by html_sanitize as if they were emails adresses. Task: 1915251 closes odoo/odoo#30326
This commit is contained in:
@@ -281,6 +281,11 @@ class TestSanitizer(unittest.TestCase):
|
||||
self.assertNotIn('<title>404 - Not Found</title>', html)
|
||||
self.assertIn('<h1>404 - Not Found</h1>', html)
|
||||
|
||||
def test_cid_with_at(self):
|
||||
img_tag = '<img src="@">'
|
||||
sanitized = html_sanitize(img_tag, sanitize_tags=False, strip_classes=True)
|
||||
self.assertEqual(img_tag, sanitized, "img with can have cid containing @ and shouldn't be escaped")
|
||||
|
||||
# ms office is currently not supported, have to find a way to support it
|
||||
# def test_30_email_msoffice(self):
|
||||
# new_html = html_sanitize(test_mail_examples.MSOFFICE_1, remove=True)
|
||||
|
||||
+1
-1
@@ -180,7 +180,7 @@ def html_sanitize(src, silent=True, sanitize_tags=True, sanitize_attributes=Fals
|
||||
part = re.compile(r"(<(([^a<>]|a[^<>\s])[^<>]*)@[^<>]+>)", re.IGNORECASE | re.DOTALL)
|
||||
# remove results containing cite="mid:email_like@address" (ex: blockquote cite)
|
||||
# cite_except = re.compile(r"^((?!cite[\s]*=['\"]).)*$", re.IGNORECASE)
|
||||
src = part.sub(lambda m: (u'cite=' not in m.group(1) and u'alt=' not in m.group(1)) and misc.html_escape(m.group(1)) or m.group(1), src)
|
||||
src = part.sub(lambda m: (u'cite=' not in m.group(1) and u'alt=' not in m.group(1) and u'src=' not in m.group(1)) and misc.html_escape(m.group(1)) or m.group(1), src)
|
||||
# html encode mako tags <% ... %> to decode them later and keep them alive, otherwise they are stripped by the cleaner
|
||||
src = src.replace(u'<%', misc.html_escape(u'<%'))
|
||||
src = src.replace(u'%>', misc.html_escape(u'%>'))
|
||||
|
||||
Reference in New Issue
Block a user