[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 `<br/>`. 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) <tde@openerp.com>
This commit is contained in:
@@ -326,7 +326,7 @@ class TestHtmlTools(BaseCase):
|
||||
for content in void_strings_samples:
|
||||
self.assertTrue(is_html_empty(content))
|
||||
|
||||
void_html_samples = ['<p><br></p>', '<p><br> </p>']
|
||||
void_html_samples = ['<p><br></p>', '<p><br> </p>', '<p><br /></p >']
|
||||
for content in void_html_samples:
|
||||
self.assertTrue(is_html_empty(content), 'Failed with %s' % content)
|
||||
|
||||
|
||||
+1
-1
@@ -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())
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user