1.9.2 is on stable branch stable
authorDavid Douard <david.douard@logilab.fr>
Fri, 03 Feb 2012 14:37:48 +0100
branchstable
changeset 269 ad9bbec7f44b
parent 266 d35a7aac025d (current diff)
parent 268 955a7e998bc1 (diff)
child 270 9ba13e38f49f
1.9.2 is on stable branch
--- a/test/unittest_blog.py	Mon Jan 17 18:56:26 2011 +0100
+++ b/test/unittest_blog.py	Fri Feb 03 14:37:48 2012 +0100
@@ -29,6 +29,27 @@
         mail = MAILBOX[1]
         self.assertEqual(mail.subject, '[data] yes')
 
+    def test_rss(self):
+        req = self.request()
+        cubicweb_blog = req.create_entity('Blog', title=u'cubicweb',
+                                          description=u"cubicweb c'est beau")
+        content = u"""
+<style> toto </style> tutu <style class=macin> toto
+</style>
+tutu
+tutu
+<style></style>
+
+<tag>tutu</tag>
+
+"""
+        blog_entry_1 = req.create_entity('BlogEntry', title=u"hop",
+                                         content=content, content_format=u"text/html")
+        blog_entry_1.set_relations(entry_of=cubicweb_blog)
+
+        xml = blog_entry_1.view('rssitem')
+        self.assertEquals(xml.count("toto"), 0)
+        self.assertEquals(xml.count("tutu"), content.count("tutu"))
 
 if __name__ == '__main__':
     unittest_main()
--- a/views/entry.py	Mon Jan 17 18:56:26 2011 +0100
+++ b/views/entry.py	Fri Feb 03 14:37:48 2012 +0100
@@ -6,6 +6,8 @@
 """
 __docformat__ = "restructuredtext en"
 
+import re
+
 from calendar import monthrange
 from datetime import datetime
 
@@ -16,6 +18,7 @@
 from cubicweb.selectors import paginated_rset, sorted_rset, is_instance
 from cubicweb.web import uicfg
 from cubicweb.web.views import primary, baseviews, calendar, navigation, workflow
+from cubicweb.web.views.xmlrss import RSSItemView
 
 _pvs = uicfg.primaryview_section
 _pvs.tag_attribute(('BlogEntry', 'title'), 'hidden')
@@ -227,3 +230,20 @@
         self._cw.add_css('cubes.blog.css')
         entity = self.cw_rset.get_entity(row, col)
         self.w(format_microblog(entity))
+
+_CLEAN_STYLE_RE = re.compile(r'<style .*?</style>', re.MULTILINE | re.DOTALL)
+
+class BlogEntryRSSItemView(RSSItemView):
+    __select__ = is_instance('BlogEntry')
+
+    def render_description(self, entity):
+        """
+        Make sure generated XML for RSS is "valid", ie. do not
+        contains <style> tags
+
+        Note that this *should* not happen (style tags there), but
+        browser tolerate them.
+        """
+        htmlcontent = entity.dc_description(format='text/html')
+        htmlcontent = _CLEAN_STYLE_RE.sub('', htmlcontent)
+        self._marker('description', htmlcontent)