From c63ffed24d07d3d0294f443f71aa641cfd89bbba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 15 Jan 2014 15:27:09 +0100 Subject: [PATCH] [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 --- openerp/tests/test_mail.py | 2 +- openerp/tools/mail.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/openerp/tests/test_mail.py b/openerp/tests/test_mail.py index 3dbae1473b0..7d177aba937 100755 --- a/openerp/tests/test_mail.py +++ b/openerp/tests/test_mail.py @@ -35,7 +35,7 @@ class TestSanitizer(unittest2.TestCase): def test_basic_sanitizer(self): cases = [ ("yop", "

yop

"), # simple - ("lala

yop

xxx", "

lala

yop

xxx
"), # trailing text + ("lala

yop

xxx", "

lala

yop

xxx"), # trailing text ("Merci à l'intérêt pour notre produit.nous vous contacterons bientôt. Merci", u"

Merci à l'intérêt pour notre produit.nous vous contacterons bientôt. Merci

"), # unicode ] diff --git a/openerp/tools/mail.py b/openerp/tools/mail.py index 3148083908a..4b686f0af34 100644 --- a/openerp/tools/mail.py +++ b/openerp/tools/mail.py @@ -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 = '

Unknown error when sanitizing

' + + # this is ugly, but lxml/etree tostring want to put everything in a 'div' that breaks the editor -> remove that + if cleaned.startswith('
') and cleaned.endswith('
'): + cleaned = cleaned[5:-6] + return cleaned