From a3e2beeeaee733b35215c46dde9a6c8c2a1a5e37 Mon Sep 17 00:00:00 2001 From: souliane Date: Wed, 12 Feb 2014 15:23:15 +0100 Subject: [PATCH] plugin XEP_0277: check for XHTML namespace and decapsulate the content from the main div container --- src/plugins/plugin_xep_0277.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/plugins/plugin_xep_0277.py b/src/plugins/plugin_xep_0277.py index 14fbdf74..58ff246b 100755 --- a/src/plugins/plugin_xep_0277.py +++ b/src/plugins/plugin_xep_0277.py @@ -121,8 +121,8 @@ class XEP_0277(object): except KeyError: content_type = 'text' if content_type == 'xhtml': - # TODO: proper check of body namespace - microblog_data['%s_xhtml' % key] = yield self.host.plugins["TEXT-SYNTAXES"].clean_xhtml(attr.text) + text = self.__decapsulateExtraNS(attr.text) + microblog_data['%s_xhtml' % key] = yield self.host.plugins["TEXT-SYNTAXES"].clean_xhtml(text) else: microblog_data[key] = attr.text if key not in microblog_data and ('%s_xhtml' % key) in microblog_data: @@ -173,6 +173,16 @@ class XEP_0277(object): defer.returnValue(microblog_data) + def __decapsulateExtraNS(self, text): + """Check for XHTML namespace and decapsulate the content so the user + who wants to modify an entry will see the text that he entered. Also + this avoids successive encapsulation with a new
...
at + each modification (encapsulation is done in self.data2entry)""" + elt = ElementParser()(text) + if elt.uri != NS_XHTML: + raise exceptions.DataError(_('Content of type XHTML must declare its namespace!')) + return elt.firstChildElement().toXml() + def microblogCB(self, itemsEvent, profile): d = defer.Deferred()