You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/06/21 23:34:17 UTC

[05/38] git commit: [#6230] Don't escape html in text/html feed entries

[#6230] Don't escape html in text/html feed entries

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/3be1c6c9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/3be1c6c9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/3be1c6c9

Branch: refs/heads/cj/6272
Commit: 3be1c6c9bff7e12e02ae4112004ef3a15cadccb8
Parents: 98125cc
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Mon Jun 10 20:57:35 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Jun 13 20:20:39 2013 +0000

----------------------------------------------------------------------
 ForgeBlog/forgeblog/command/rssfeeds.py    |  5 ++-
 ForgeBlog/forgeblog/tests/test_commands.py | 51 +++++++++++++++----------
 2 files changed, 33 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3be1c6c9/ForgeBlog/forgeblog/command/rssfeeds.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/command/rssfeeds.py b/ForgeBlog/forgeblog/command/rssfeeds.py
index 2b7f6e9..9f44fd4 100644
--- a/ForgeBlog/forgeblog/command/rssfeeds.py
+++ b/ForgeBlog/forgeblog/command/rssfeeds.py
@@ -145,9 +145,10 @@ class RssFeedsCommand(base.BlogCommand):
     def process_entry(self, e, appid):
         title = e.title
         allura_base.log.info(" ...entry '%s'", title)
-        if 'content' in e:
+        parsed_content = filter(None, e.get('content') or [e.get('summary_detail')])
+        if parsed_content:
             content = u''
-            for ct in e.content:
+            for ct in parsed_content:
                 if ct.type != 'text/html':
                     content += plain2markdown(ct.value)
                 else:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3be1c6c9/ForgeBlog/forgeblog/tests/test_commands.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/tests/test_commands.py b/ForgeBlog/forgeblog/tests/test_commands.py
index 2b8363d..472efda 100644
--- a/ForgeBlog/forgeblog/tests/test_commands.py
+++ b/ForgeBlog/forgeblog/tests/test_commands.py
@@ -60,6 +60,8 @@ def _mock_feed(*entries):
         entry['updated_parsed'] = entry['updated'].timetuple()
         if 'content' in entry:
             entry['content'] = [attrdict(type=entry['content_type'], value=entry['content'])]
+        if 'summary_detail' in entry:
+            entry['summary_detail'] = attrdict(entry['summary_detail'])
         feed.entries.append(entry)
 
     return feed
@@ -68,21 +70,33 @@ _mock_feed.i = 0
 @skipif(module_not_available('html2text'))
 @mock.patch.object(feedparser, 'parse')
 def test_pull_rss_feeds(parsefeed):
+    html_content = (
+        "<p>1. foo</p>\n"
+        "\n"
+        "<p>\n"
+        "#foo bar <a href='baz'>baz</a>\n"
+        "foo bar\n"
+        "</p>\n"
+        "\n"
+        "<p>#foo bar <a href='baz'>\n"
+        "baz\n"
+        "</a></p>\n"
+    )
+
+    rendered_html_content = "\n".join([
+       r"1\. foo",
+        "",
+       r"\#foo bar [baz](baz) foo bar ",
+        "",
+       r"\#foo bar [ baz ](baz)",
+        " [link](http://example.com/)",
+    ])
+
     parsefeed.return_value = _mock_feed(
         dict(title='Test', subtitle='test', summary='This is a test'),
         dict(content_type='text/plain', content='Test feed'),
-        dict(content_type='text/html', content=
-                "<p>1. foo</p>\n"
-                "\n"
-                "<p>\n"
-                "#foo bar <a href='baz'>baz</a>\n"
-                "foo bar\n"
-                "</p>\n"
-                "\n"
-                "<p>#foo bar <a href='baz'>\n"
-                "baz\n"
-                "</a></p>\n"
-            ),
+        dict(content_type='text/html', content=html_content),
+        dict(summary_detail=dict(type='text/html', value=html_content)),
     )
 
     base_app =  M.AppConfig.query.find().all()[0]
@@ -102,21 +116,16 @@ def test_pull_rss_feeds(parsefeed):
     cmd.command()
     parsefeed.assert_called_with('http://example.com/news/feed/')
     posts = BM.BlogPost.query.find({'app_config_id': tmp_app._id}).sort('timestamp', 1)
-    assert_equal(posts.count(), 3)
+    assert_equal(posts.count(), 4)
     posts = posts.all()
     assert_equal(posts[0].title, 'Test')
     assert_equal(posts[0].text, 'This is a test [link](http://example.com/)')
     assert_equal(posts[1].title, 'Default Title 2')
     assert_equal(posts[1].text, 'Test feed [link](http://example.com/)')
     assert_equal(posts[2].title, 'Default Title 3')
-    assert_equal(posts[2].text, "\n".join([
-       r"1\. foo",
-        "",
-       r"\#foo bar [baz](baz) foo bar ",
-        "",
-       r"\#foo bar [ baz ](baz)",
-        " [link](http://example.com/)",
-    ]))
+    assert_equal(posts[2].text, rendered_html_content)
+    assert_equal(posts[3].title, 'Default Title 4')
+    assert_equal(posts[3].text, rendered_html_content)
 
 @skipif(module_not_available('html2text'))
 def test_plaintext_preprocessor():