From 5af661da7d62605127566124bf5f0e2ee84432db Mon Sep 17 00:00:00 2001 From: Dharmraj Jhala Date: Wed, 17 Jun 2020 11:55:25 +0000 Subject: [PATCH] [FIX] tools: fix tool method to check empty html content Since a recent commit[1], we have a utility method in tools named 'is_html_empty' that checks whether the given html content is void(containing only formatting tags) or not. However, the re from this method does not consider the case of self closing tags, fox ex `
`. In such cases, the method returns Falsy value even if the content is void. This commit fixes the issue by considering self-closing void tags in the regular expression. commit[1] - https://github.com/odoo/odoo/commit/974f512f5f5d3b9f80a8c3fcde290e4f55cf1230 Task - 2267689 closes odoo/odoo#53167 X-original-commit: 0fd6c9388dc959a9b6b7828850683175edb05b9d Signed-off-by: Thibault Delavallee (tde) --- odoo/addons/base/tests/test_mail.py | 2 +- odoo/tools/mail.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/odoo/addons/base/tests/test_mail.py b/odoo/addons/base/tests/test_mail.py index 3fdadaba373..5973fd623fb 100644 --- a/odoo/addons/base/tests/test_mail.py +++ b/odoo/addons/base/tests/test_mail.py @@ -326,7 +326,7 @@ class TestHtmlTools(BaseCase): for content in void_strings_samples: self.assertTrue(is_html_empty(content)) - void_html_samples = ['


', '


'] + void_html_samples = ['


', '


', '


'] for content in void_html_samples: self.assertTrue(is_html_empty(content), 'Failed with %s' % content) diff --git a/odoo/tools/mail.py b/odoo/tools/mail.py index c37f6dcc369..eed992e142f 100644 --- a/odoo/tools/mail.py +++ b/odoo/tools/mail.py @@ -276,7 +276,7 @@ def is_html_empty(html_content): """ if not html_content: return True - tag_re = re.compile(r'\<\s*\/?(?:p|div|span|br|b|i)\s*\>') + tag_re = re.compile(r'\<\s*\/?(?:p|div|span|br|b|i)\s*/?\s*\>') return not bool(re.sub(tag_re, '', html_content).strip())