[IMP] tools: mail: the cleaner, by parsing and serializing the html content,

encapsulatse the whole content inside a div. This means that html fields are
not editor-clean after being sanitized, because a div has been inserted as root
element. Removing this element allows to have snippets that can be dragged,
dropped, or to insert new snippets inside edited html content in html fields.

[IMP] tools: tests: mail: updated a test accordingly

bzr revid: tde@openerp.com-20140115142709-e4951b4nc06sfxf0
This commit is contained in:
Thibault Delavallée
2014-01-15 15:27:09 +01:00
parent 2c4600f242
commit c63ffed24d
2 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ class TestSanitizer(unittest2.TestCase):
def test_basic_sanitizer(self):
cases = [
("yop", "<p>yop</p>"), # simple
("lala<p>yop</p>xxx", "<div><p>lala</p><p>yop</p>xxx</div>"), # trailing text
("lala<p>yop</p>xxx", "<p>lala</p><p>yop</p>xxx"), # trailing text
("Merci à l'intérêt pour notre produit.nous vous contacterons bientôt. Merci",
u"<p>Merci à l'intérêt pour notre produit.nous vous contacterons bientôt. Merci</p>"), # unicode
]
+5
View File
@@ -106,6 +106,11 @@ def html_sanitize(src, silent=True, strict=False):
raise
logger.warning('unknown error obtained when sanitizing %r', src, exc_info=True)
cleaned = '<p>Unknown error when sanitizing</p>'
# this is ugly, but lxml/etree tostring want to put everything in a 'div' that breaks the editor -> remove that
if cleaned.startswith('<div>') and cleaned.endswith('</div>'):
cleaned = cleaned[5:-6]
return cleaned