From 28d6468bc495d57a951991ad44061d70e012780b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 28 Jun 2021 13:38:51 +0000 Subject: [PATCH] [FIX] tools: better support 'almost empty' content from editor It seems quite easy to have a void content in the currently new editor that actually holds a lot of undesired information, notably a font tag. This is annoying when having behavior based on an html field being empty or not. In this commit we therefore improve definition of an 'empty' html field. Task ID-2532529 PR odoo/odoo#71793 --- odoo/addons/base/tests/test_mail.py | 16 ++++++++++++---- odoo/tools/mail.py | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/odoo/addons/base/tests/test_mail.py b/odoo/addons/base/tests/test_mail.py index 755b959f573..4913558bc60 100644 --- a/odoo/addons/base/tests/test_mail.py +++ b/odoo/addons/base/tests/test_mail.py @@ -328,13 +328,21 @@ 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) - valid_html_samples = ['


1

', '

1

', '

Hello World

', - '

Hello World

'] + valid_html_samples = [ + '


1

', '

1

', '

Hello World

', + '

Hello World

', + '

W

', + ] for content in valid_html_samples: self.assertFalse(is_html_empty(content)) diff --git a/odoo/tools/mail.py b/odoo/tools/mail.py index 792bb1e876b..ecda726a23f 100644 --- a/odoo/tools/mail.py +++ b/odoo/tools/mail.py @@ -280,7 +280,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+\w*)[^/>]*|\s*)/?\s*\>') + tag_re = re.compile(r'\<\s*\/?(?:p|div|span|br|b|i|font)(?:(?=\s+\w*)[^/>]*|\s*)/?\s*\>') return not bool(re.sub(tag_re, '', html_content).strip())