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()