# HG changeset patch # User souliane # Date 1392214995 -3600 # Node ID eff944ff3e139c4d4f2b2a89317daca1abacc69c # Parent 2cc0201b4613b94276f871626a8217485c20a43f plugin XEP_0277: check for XHTML namespace and decapsulate the content from the main div container diff -r 2cc0201b4613 -r eff944ff3e13 src/plugins/plugin_xep_0277.py --- a/src/plugins/plugin_xep_0277.py Wed Feb 12 15:21:00 2014 +0100 +++ b/src/plugins/plugin_xep_0277.py Wed Feb 12 15:23:15 2014 +0100 @@ -121,8 +121,8 @@ 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 @@ 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()