You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/08/03 20:57:43 UTC

[1/4] allura git commit: [#7947] remove unnecessary line breakage

Repository: allura
Updated Branches:
  refs/heads/db/7947 [created] ad029f875


[#7947] remove unnecessary line breakage


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

Branch: refs/heads/db/7947
Commit: 556a99e9d986a9ebff4b84c36bf64886da02e4fd
Parents: 7075554
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Mon Aug 3 18:10:54 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Aug 3 18:10:54 2015 +0000

----------------------------------------------------------------------
 Allura/allura/lib/markdown_extensions.py | 36 +++++++++------------------
 Allura/allura/model/project.py           |  3 +--
 2 files changed, 13 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/556a99e9/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index 9a68e1a..83e8069 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -74,18 +74,14 @@ class CommitMessageExtension(markdown.Extension):
         md.registerExtension(self)
         # remove default preprocessors and add our own
         md.preprocessors.clear()
-        md.preprocessors['trac_refs'] = PatternReplacingProcessor(
-            TracRef1(), TracRef2(), TracRef3(self.app))
+        md.preprocessors['trac_refs'] = PatternReplacingProcessor(TracRef1(), TracRef2(), TracRef3(self.app))
         # remove all inlinepattern processors except short refs and links
         md.inlinePatterns.clear()
-        md.inlinePatterns["link"] = markdown.inlinepatterns.LinkPattern(
-            markdown.inlinepatterns.LINK_RE, md)
-        md.inlinePatterns['short_reference'] = ForgeLinkPattern(
-            markdown.inlinepatterns.SHORT_REF_RE, md, ext=self)
+        md.inlinePatterns["link"] = markdown.inlinepatterns.LinkPattern(markdown.inlinepatterns.LINK_RE, md)
+        md.inlinePatterns['short_reference'] = ForgeLinkPattern(markdown.inlinepatterns.SHORT_REF_RE, md, ext=self)
         # remove all default block processors except for paragraph
         md.parser.blockprocessors.clear()
-        md.parser.blockprocessors['paragraph'] = \
-            markdown.blockprocessors.ParagraphProcessor(md.parser)
+        md.parser.blockprocessors['paragraph'] = markdown.blockprocessors.ParagraphProcessor(md.parser)
         # wrap artifact link text in square brackets
         self.forge_link_tree_processor = ForgeLinkTreeProcessor(md)
         md.treeprocessors['links'] = self.forge_link_tree_processor
@@ -253,31 +249,23 @@ class ForgeExtension(markdown.Extension):
         # https://github.com/waylan/Python-Markdown/issues/52
         md.preprocessors['html_block'].markdown_in_raw = True
         md.preprocessors['fenced-code'] = FencedCodeProcessor()
-        md.preprocessors.add('plain_text_block',
-                             PlainTextPreprocessor(md), "_begin")
-        md.preprocessors.add(
-            'macro_include', ForgeMacroIncludePreprocessor(md), '_end')
+        md.preprocessors.add('plain_text_block', PlainTextPreprocessor(md), "_begin")
+        md.preprocessors.add('macro_include', ForgeMacroIncludePreprocessor(md), '_end')
         # this has to be before the 'escape' processor, otherwise weird
         # placeholders are inserted for escaped chars within urls, and then the
         # autolink can't match the whole url
-        md.inlinePatterns.add('autolink_without_brackets', AutolinkPattern(
-            r'(http(?:s?)://[a-zA-Z0-9./\-\\_%?&=+#;~:!]+)', md), '<escape')
+        md.inlinePatterns.add('autolink_without_brackets', AutolinkPattern(r'(http(?:s?)://[a-zA-Z0-9./\-\\_%?&=+#;~:!]+)', md), '<escape')
         # replace the link pattern with our extended version
-        md.inlinePatterns['link'] = ForgeLinkPattern(
-            markdown.inlinepatterns.LINK_RE, md, ext=self)
-        md.inlinePatterns['short_reference'] = ForgeLinkPattern(
-            markdown.inlinepatterns.SHORT_REF_RE, md, ext=self)
+        md.inlinePatterns['link'] = ForgeLinkPattern(markdown.inlinepatterns.LINK_RE, md, ext=self)
+        md.inlinePatterns['short_reference'] = ForgeLinkPattern(markdown.inlinepatterns.SHORT_REF_RE, md, ext=self)
         # macro must be processed before links
-        md.inlinePatterns.add(
-            'macro', ForgeMacroPattern(MACRO_PATTERN, md, ext=self), '<link')
+        md.inlinePatterns.add('macro', ForgeMacroPattern(MACRO_PATTERN, md, ext=self), '<link')
         self.forge_link_tree_processor = ForgeLinkTreeProcessor(md)
         md.treeprocessors['links'] = self.forge_link_tree_processor
         # Sanitize HTML
         md.postprocessors['sanitize_html'] = HTMLSanitizer()
-        # Rewrite all relative links that don't start with . to have a '../'
-        # prefix
-        md.postprocessors['rewrite_relative_links'] = RelativeLinkRewriter(
-            make_absolute=self._is_email)
+        # Rewrite all relative links that don't start with . to have a '../' prefix
+        md.postprocessors['rewrite_relative_links'] = RelativeLinkRewriter(make_absolute=self._is_email)
         # Put a class around markdown content for custom css
         md.postprocessors['add_custom_class'] = AddCustomClass()
         md.postprocessors['mark_safe'] = MarkAsSafe()

http://git-wip-us.apache.org/repos/asf/allura/blob/556a99e9/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index b45af77..cef25bc 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -859,8 +859,7 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
         named_roles = security.RoleCache(
             g.credentials,
             g.credentials.project_roles(project_id=self.root_project._id).named)
-        uids = [
-            uid for uid in named_roles.userids_that_reach if uid is not None]
+        uids = [uid for uid in named_roles.userids_that_reach if uid is not None]
         return list(User.query.find({'_id': {'$in': uids}, 'disabled': False, 'pending': False}))
 
     def users_with_role(self, *role_names):


[3/4] allura git commit: [#7947] fix minor HTML changes in tests, also artifact links now have trailing slashes again (they went away in [8da7c57] for some reason)

Posted by br...@apache.org.
[#7947] fix minor HTML changes in tests, also artifact links now have trailing slashes again (they went away in [8da7c57] for some reason)


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

Branch: refs/heads/db/7947
Commit: dd3ca5bf6fc5be91a2ef29012c6a59c62cf85a8a
Parents: e0e2f0c
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Mon Aug 3 18:47:15 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Aug 3 18:55:26 2015 +0000

----------------------------------------------------------------------
 Allura/allura/tests/functional/test_root.py     |   2 +-
 Allura/allura/tests/test_globals.py             | 114 ++++++++++---------
 Allura/allura/tests/test_helpers.py             |   2 +-
 .../forgeblog/tests/unit/test_blog_post.py      |   2 +-
 .../forgetracker/tests/functional/test_root.py  |  10 +-
 5 files changed, 68 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/dd3ca5bf/Allura/allura/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_root.py b/Allura/allura/tests/functional/test_root.py
index 8f29b31..bc54d65 100644
--- a/Allura/allura/tests/functional/test_root.py
+++ b/Allura/allura/tests/functional/test_root.py
@@ -149,7 +149,7 @@ class TestRootController(TestController):
         n = M.Neighborhood.query.get(name='Projects')
         r = self.app.get(
             '/nf/markdown_to_html?markdown=*aaa*bb[wiki:Home]&project=test&app=bugs&neighborhood=%s' % n._id, validate_chunk=True)
-        assert '<p><em>aaa</em>bb<a class="alink" href="/p/test/wiki/Home">[wiki:Home]</a></p>' in r, r
+        assert '<p><em>aaa</em>bb<a class="alink" href="/p/test/wiki/Home/">[wiki:Home]</a></p>' in r, r
 
     def test_slash_redirect(self):
         self.app.get('/p', status=301)

http://git-wip-us.apache.org/repos/asf/allura/blob/dd3ca5bf/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 91565ae..0203969 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -48,6 +48,9 @@ from allura.tests import decorators as td
 from forgewiki import model as WM
 from forgeblog import model as BM
 
+def squish_spaces(text):
+    return re.sub(r'\s+', ' ', text)
+
 
 def setUp():
     """Method called by nose once before running the package.  Some functions need it run again to reset data"""
@@ -210,12 +213,14 @@ def test_macro_members():
     p_test.add_user(M.User.by_username('test-user'), ['Developer'])
     p_test.add_user(M.User.by_username('test-user-0'), ['Member'])
     ThreadLocalORMSession.flush_all()
-    r = g.markdown_wiki.convert('[[members limit=2]]')
-    assert_equal(r, '<div class="markdown_content"><h6>Project Members:</h6>\n'
-                 '<ul class="md-users-list">\n'
-                 '<li><a href="/u/test-admin">Test Admin</a> (admin)</li><li><a href="/u/test-user">Test User</a></li>\n'
-                 '<li class="md-users-list-more"><a href="/p/test/_members">All Members</a></li>\n'
-                 '</ul>\n'
+    r = g.markdown_wiki.convert('[[members limit=2]]').replace('\t','').replace('\n','')
+    assert_equal(r,
+                 '<div class="markdown_content"><h6>Project Members:</h6>'
+                 '<ul class="md-users-list">'
+                 '<li><a href="/u/test-admin/">Test Admin</a> (admin)</li>'
+                 '<li><a href="/u/test-user/">Test User</a></li>'
+                 '<li class="md-users-list-more"><a href="/p/test/_members">All Members</a></li>'
+                 '</ul>'
                  '</div>')
 
 
@@ -224,10 +229,11 @@ def test_macro_members_escaping():
     user = M.User.by_username('test-admin')
     user.display_name = u'Test Admin <script>'
     r = g.markdown_wiki.convert('[[members]]')
-    assert_equal(r, u'<div class="markdown_content"><h6>Project Members:</h6>\n'
-                 u'<ul class="md-users-list">\n'
-                 u'<li><a href="/u/test-admin">Test Admin &lt;script&gt;</a> (admin)</li>\n'
-                 u'</ul>\n</div>')
+    assert_equal(r.replace('\n', '').replace('\t', ''),
+                 u'<div class="markdown_content"><h6>Project Members:</h6>'
+                 u'<ul class="md-users-list">'
+                 u'<li><a href="/u/test-admin/">Test Admin &lt;script&gt;</a> (admin)</li>'
+                 u'</ul></div>')
 
 
 @with_setup(setUp)
@@ -236,8 +242,11 @@ def test_macro_project_admins():
     user.display_name = u'Test Ã…dmin <script>'
     with h.push_context('test', neighborhood='Projects'):
         r = g.markdown_wiki.convert('[[project_admins]]')
-    assert_equal(
-        r, u'<div class="markdown_content"><h6>Project Admins:</h6>\n<ul class="md-users-list">\n<li><a href="/u/test-admin">Test \xc5dmin &lt;script&gt;</a></li>\n</ul>\n</div>')
+    assert_equal(r.replace('\n', ''),
+                 u'<div class="markdown_content"><h6>Project Admins:</h6>'
+                 u'<ul class="md-users-list">'
+                 u'    <li><a href="/u/test-admin/">Test \xc5dmin &lt;script&gt;</a></li>'
+                 u'</ul></div>')
 
 
 @with_setup(setUp)
@@ -249,7 +258,7 @@ def test_macro_project_admins_one_br():
     with h.push_config(c, project=p_test):
         r = g.markdown_wiki.convert('[[project_admins]]\n[[download_button]]')
 
-    assert not '</a><br /><br /><a href=' in r, r
+    assert not '</a><br/><br/><a href=' in r, r
     assert '</a></li><li><a href=' in r, r
 
 
@@ -272,17 +281,17 @@ def test_macro_include_no_extra_br():
         md = '[[include ref=Include_1]]\n[[include ref=Include_2]]\n[[include ref=Include_3]]'
         html = g.markdown_wiki.convert(md)
 
-    expected_html = '''
-<div class="markdown_content">
-<p>
-<div><div class="markdown_content"><p>included page 1</p></div></div>
-<div><div class="markdown_content"><p>included page 2</p></div></div>
-<div><div class="markdown_content"><p>included page 3</p></div></div>
-</p>
-<p></p>
+    expected_html = '''<div class="markdown_content"><p></p><div>
+<div class="markdown_content"><p>included page 1</p></div>
+</div>
+<div>
+<div class="markdown_content"><p>included page 2</p></div>
+</div>
+<div>
+<div class="markdown_content"><p>included page 3</p></div>
 </div>
-'''.strip().replace('\n', '')
-    assert html.strip().replace('\n', '') == expected_html, html
+<p></p></div>'''
+    assert_equal(squish_spaces(html), squish_spaces(expected_html))
 
 @with_setup(setUp, tearDown)
 @td.with_wiki
@@ -324,10 +333,9 @@ def test_macro_embed(oembed_fetch):
         "html": '<iframe width="480" height="270" src="http://www.youtube.com/embed/kOLpSPEA72U?feature=oembed" frameborder="0" allowfullscreen></iframe>)',
         "title": "Nature's 3D Printer: MIND BLOWING Cocoon in Rainforest - Smarter Every Day 94",
     }
-    r = g.markdown_wiki.convert(
-        '[[embed url=http://www.youtube.com/watch?v=kOLpSPEA72U]]')
-    assert_in('<div class="grid-20"><iframe height="270" src="https://www.youtube.com/embed/kOLpSPEA72U?feature=oembed" width="480"></iframe>\n</div>',
-              r)
+    r = g.markdown_wiki.convert('[[embed url=http://www.youtube.com/watch?v=kOLpSPEA72U]]')
+    assert_in('<div class="grid-20"><iframe height="270" src="https://www.youtube.com/embed/kOLpSPEA72U?feature=oembed" width="480"></iframe></div>',
+              r.replace('\n', ''))
 
 
 def test_macro_embed_notsupported():
@@ -357,29 +365,29 @@ def test_wiki_artifact_links():
     assert 'See <span>[18:13:49]</span>' in text, text
     with h.push_context('test', 'wiki', neighborhood='Projects'):
         text = g.markdown.convert('Read [here](Home) about our project')
-        assert '<a class="" href="/p/test/wiki/Home">here</a>' in text, text
+        assert '<a class="" href="/p/test/wiki/Home/">here</a>' in text, text
         text = g.markdown.convert('[Go home](test:wiki:Home)')
-        assert '<a class="" href="/p/test/wiki/Home">Go home</a>' in text, text
+        assert '<a class="" href="/p/test/wiki/Home/">Go home</a>' in text, text
         text = g.markdown.convert('See [test:wiki:Home]')
-        assert '<a class="alink" href="/p/test/wiki/Home">[test:wiki:Home]</a>' in text, text
+        assert '<a class="alink" href="/p/test/wiki/Home/">[test:wiki:Home]</a>' in text, text
 
 
 def test_markdown_links():
     with patch.dict(tg.config, {'nofollow_exempt_domains': 'foobar.net'}):
-        text = g.markdown.convert(
-            'Read [here](http://foobar.net/) about our project')
-        assert_in('class="" href="http://foobar.net">here</a> about', text)
+        text = g.markdown.convert('Read [here](http://foobar.net/) about our project')
+        assert_in('class="" href="http://foobar.net/">here</a> about', text)
 
-    text = g.markdown.convert(
-        'Read [here](http://foobar.net/) about our project')
-    assert_in('class="" href="http://foobar.net" rel="nofollow">here</a> about', text)
+    text = g.markdown.convert('Read [here](http://foobar.net/) about our project')
+    assert_in('class="" href="http://foobar.net/" rel="nofollow">here</a> about', text)
 
     text = g.markdown.convert('Read [here](/p/foobar/blah) about our project')
     assert_in('class="" href="/p/foobar/blah">here</a> about', text)
 
+    text = g.markdown.convert('Read [here](/p/foobar/blah/) about our project')
+    assert_in('class="" href="/p/foobar/blah/">here</a> about', text)
+
     text = g.markdown.convert('Read <http://foobar.net/> about our project')
-    assert_in(
-        'href="http://foobar.net" rel="nofollow">http://foobar.net/</a> about', text)
+    assert_in('href="http://foobar.net/" rel="nofollow">http://foobar.net/</a> about', text)
 
 
 def test_markdown_and_html():
@@ -390,11 +398,9 @@ def test_markdown_and_html():
 
 def test_markdown_within_html():
     with h.push_context('test', neighborhood='Projects'):
-        r = g.markdown_wiki.convert(
-            '<div style="float:left" markdown>**blah**</div>')
-    assert '''<div style="float: left;">
-<p><strong>blah</strong></p>
-</div>''' in r, r
+        r = g.markdown_wiki.convert('<div style="float:left" markdown>**blah**</div>')
+    assert_in('<div style="float: left;"><p><strong>blah</strong></p></div>',
+              r.replace('\n', ''))
 
 
 def test_markdown_with_html_comments():
@@ -413,16 +419,15 @@ def test_markdown_big_text():
 def test_markdown_basics():
     with h.push_context('test', 'wiki', neighborhood='Projects'):
         text = g.markdown.convert('# Foo!\n[Home]')
-        assert '<a class="alink" href="/p/test/wiki/Home">[Home]</a>' in text, text
+        assert '<a class="alink" href="/p/test/wiki/Home/">[Home]</a>' in text, text
         text = g.markdown.convert('# Foo!\n[Rooted]')
         assert '<a href=' not in text, text
 
-    assert '<br' in g.markdown.convert(
-        'Multi\nLine'), g.markdown.convert('Multi\nLine')
+    assert '<br' in g.markdown.convert('Multi\nLine'), g.markdown.convert('Multi\nLine')
     assert '<br' not in g.markdown.convert('Multi\n\nLine')
 
     g.markdown.convert("<class 'foo'>")  # should not raise an exception
-    assert '<br>' not in g.markdown.convert('''# Header
+    assert '<br' not in g.markdown.convert('''# Header
 
 Some text in a regular paragraph
 
@@ -446,7 +451,7 @@ def test_markdown_autolink():
     # beginning of doc
     assert_in('<a href=', g.markdown.convert('http://domain.net abc'))
     # beginning of a line
-    assert_in('<br />\n<a href="http://',
+    assert_in('<br/>\n<a href="http://',
               g.markdown.convert('foobar\nhttp://domain.net abc'))
     # no conversion of these urls:
     assert_in('a blahttp://sdf.com z',
@@ -461,8 +466,7 @@ def test_markdown_autolink():
 def test_markdown_autolink_with_escape():
     # \_ is unnecessary but valid markdown escaping and should be considered as a regular underscore
     # (it occurs during html2text conversion during project migrations)
-    r = g.markdown.convert(
-        'a http://www.phpmyadmin.net/home\_page/security/\#target b')
+    r = g.markdown.convert('a http://www.phpmyadmin.net/home\_page/security/\#target b')
     assert 'href="http://www.phpmyadmin.net/home_page/security/#target"' in r, r
 
 
@@ -588,7 +592,7 @@ def test_myprojects_macro():
     for p in c.user.my_projects():
         if p.deleted or p.is_nbhd_project:
             continue
-        proj_title = '<h2><a href="%s">%s</a></h2>' % (p.url().rstrip('/'), p.name)
+        proj_title = '<h2><a href="%s">%s</a></h2>' % (p.url(), p.name)
         assert_in(proj_title, r)
 
     h.set_context('u/test-user-1', 'wiki', neighborhood='Users')
@@ -597,7 +601,7 @@ def test_myprojects_macro():
     for p in user.my_projects():
         if p.deleted or p.is_nbhd_project:
             continue
-        proj_title = '<h2><a href="%s">%s</a></h2>' % (p.url().rstrip('/'), p.name)
+        proj_title = '<h2><a href="%s">%s</a></h2>' % (p.url(), p.name)
         assert_in(proj_title, r)
 
 
@@ -625,9 +629,11 @@ def test_hideawards_macro():
 
     with h.push_context(p_nbhd.neighborhood_project._id):
         r = g.markdown_wiki.convert('[[projects]]')
-        assert '<div class="feature">\n<a href="http://award.org" title="Winner!" rel="nofollow">Award short</a>\n</div>' in r, r
+        assert_in('<div class="feature"> <a href="http://award.org" rel="nofollow" title="Winner!">Award short</a> </div>',
+                  squish_spaces(r))
+
         r = g.markdown_wiki.convert('[[projects show_awards_banner=False]]')
-        assert '<div class="feature">\n<a href="http://award.org" title="Winner!" rel="nofollow">Award short</a>\n</div>' not in r, r
+        assert_not_in('Award short', r)
 
 
 def get_project_names(r):

http://git-wip-us.apache.org/repos/asf/allura/blob/dd3ca5bf/Allura/allura/tests/test_helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index 49032eb..22d5b94 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -250,7 +250,7 @@ def test_render_any_markup_formatting():
                   '<div class="markdown_content"><h3 id="foo">foo</h3>\n'
                   '<div class="codehilite"><pre><span class="nt">'
                   '&lt;script&gt;</span>alert(1)<span class="nt">'
-                  '&lt;/script&gt;</span> bar\n</pre></div>\n</div>')
+                  '&lt;/script&gt;</span> bar\n</pre></div>\n\n</div>')
 
 
 class AuditLogMock(Mock):

http://git-wip-us.apache.org/repos/asf/allura/blob/dd3ca5bf/ForgeBlog/forgeblog/tests/unit/test_blog_post.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/tests/unit/test_blog_post.py b/ForgeBlog/forgeblog/tests/unit/test_blog_post.py
index 34842c5..fadfcf0 100644
--- a/ForgeBlog/forgeblog/tests/unit/test_blog_post.py
+++ b/ForgeBlog/forgeblog/tests/unit/test_blog_post.py
@@ -132,6 +132,6 @@ class TestHtmlPreview(BlogTestWithModel):
                     'fugiat nulla pariatur. Excepteur sint occaecat cupidatat '
                     'non proident, sunt in culpa qui officia deserunt mollit '
                     'anim id est laborum.... '
-                    '<a class="" href="/p/test/blog/%s/%02i/untitled">'
+                    '<a class="" href="/p/test/blog/%s/%02i/untitled/">'
                     'read more</a></p></div>') % (now.year, now.month)
         assert_equal(self._make_post(text).html_text_preview, expected)

http://git-wip-us.apache.org/repos/asf/allura/blob/dd3ca5bf/ForgeTracker/forgetracker/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index 89041d7..47c9aab 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -984,8 +984,8 @@ class TestFunctionalController(TrackerTestController):
         assert_not_in('Tickets: <s>#1</s>', r)
         assert_in('Tickets: <s>#2</s>', r)
 
-        assert_in('<a class="alink" href="/p/test/bugs/1">[#1]</a>', r.body)
-        assert_in('<a class="alink strikethrough" href="/p/test/bugs/2">[#2]</a>', r.body)
+        assert_in('<a class="alink" href="/p/test/bugs/1/">[#1]</a>', r.body)
+        assert_in('<a class="alink strikethrough" href="/p/test/bugs/2/">[#2]</a>', r.body)
 
     def test_ticket_view_editable(self):
         summary = 'test ticket view page can be edited'
@@ -2381,7 +2381,7 @@ class TestFunctionalController(TrackerTestController):
             return_path, rcpts, body = _client.sendmail.call_args[0]
             body = body.split('\n')
             assert 'Subject: [test:bugs] #1 test <h2> ticket' in body
-            assert_in('<p><strong> <a class="alink" href="http://localhost:8080/p/test/bugs/1">[bugs:#1]</a> test &lt;h2&gt; ticket</strong></p>', body)
+            assert_in('<p><strong> <a class="alink" href="http://localhost:8080/p/test/bugs/1/">[bugs:#1]</a> test &lt;h2&gt; ticket</strong></p>', body)
 
     @patch('forgetracker.search.query_filter_choices')
     def test_multiselect(self, query_filter_choices):
@@ -3195,9 +3195,9 @@ class TestArtifactLinks(TrackerTestController):
         assert_equal(ticket_features.app.config._id, features.config._id)
 
         c.app = bugs
-        link = u'<div class="markdown_content"><p><a class="alink" href="/p/test/bugs/1">[#1]</a></p></div>'
+        link = u'<div class="markdown_content"><p><a class="alink" href="/p/test/bugs/1/">[#1]</a></p></div>'
         assert_equal(g.markdown.convert('[#1]'), link)
 
         c.app = features
-        link = u'<div class="markdown_content"><p><a class="alink" href="/p/test/features/1">[#1]</a></p></div>'
+        link = u'<div class="markdown_content"><p><a class="alink" href="/p/test/features/1/">[#1]</a></p></div>'
         assert_equal(g.markdown.convert('[#1]'), link)


[4/4] allura git commit: [#7947] don't allow any cached markdown from before this fix to be used

Posted by br...@apache.org.
[#7947] don't allow any cached markdown from before this fix to be used


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

Branch: refs/heads/db/7947
Commit: ad029f8752e8529fd7c5fe0928592ab8ed4f8c3a
Parents: dd3ca5b
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Mon Aug 3 18:49:21 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Aug 3 18:55:27 2015 +0000

----------------------------------------------------------------------
 Allura/allura/lib/app_globals.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/ad029f87/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 2a7ee5c..5d262e8 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -103,11 +103,12 @@ class ForgeMarkdown(markdown.Markdown):
                 field_name, artifact.__class__.__name__)
             return self.convert(source_text)
 
+        bugfix_rev = 2  # increment this if we need all caches to invalidated (e.g. xss in markdown rendering fixed)
         md5 = None
         # If a cached version exists and it is valid, return it.
         if cache.md5 is not None:
             md5 = hashlib.md5(source_text.encode('utf-8')).hexdigest()
-            if cache.md5 == md5 and getattr(cache, 'fix7528', False):
+            if cache.md5 == md5 and getattr(cache, 'fix7528', False) == bugfix_rev:
                 return h.html.literal(cache.html)
 
         # Convert the markdown and time the result.
@@ -128,7 +129,7 @@ class ForgeMarkdown(markdown.Markdown):
             if md5 is None:
                 md5 = hashlib.md5(source_text.encode('utf-8')).hexdigest()
             cache.md5, cache.html, cache.render_time = md5, html, render_time
-            cache.fix7528 = True  # flag to indicate good caches created after [#7528] was fixed
+            cache.fix7528 = bugfix_rev  # flag to indicate good caches created after [#7528] and other critical bugs were fixed.
 
             # Prevent cache creation from updating the mod_date timestamp.
             _session = artifact_orm_session._get()


[2/4] allura git commit: [#7947] use beautifulsoup4 for correct identification of tricky tag situations during URL rewriting

Posted by br...@apache.org.
[#7947] use beautifulsoup4 for correct identification of tricky tag situations during URL rewriting


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

Branch: refs/heads/db/7947
Commit: e0e2f0c4057a33256d59da72c73626848a1d6579
Parents: 556a99e
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Mon Aug 3 18:45:36 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Aug 3 18:55:26 2015 +0000

----------------------------------------------------------------------
 Allura/allura/lib/markdown_extensions.py | 17 ++++++-----------
 Allura/allura/tests/test_globals.py      |  7 +++++++
 requirements.txt                         |  3 ++-
 3 files changed, 15 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/e0e2f0c4/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index 83e8069..cbccf5d 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -20,7 +20,7 @@ import logging
 from urlparse import urljoin
 
 from tg import config
-from BeautifulSoup import BeautifulSoup
+from bs4 import BeautifulSoup
 import html5lib
 import html5lib.serializer
 import html5lib.filters.alphabeticalattributes
@@ -441,7 +441,8 @@ class RelativeLinkRewriter(markdown.postprocessors.Postprocessor):
         self._make_absolute = make_absolute
 
     def run(self, text):
-        soup = BeautifulSoup(text)
+        soup = BeautifulSoup(text, 'html5lib')  # 'html.parser' parser gives weird </li> behaviour with test_macro_members
+
         if self._make_absolute:
             rewrite = self._rewrite_abs
         else:
@@ -450,15 +451,9 @@ class RelativeLinkRewriter(markdown.postprocessors.Postprocessor):
             rewrite(link, 'href')
         for link in soup.findAll('img'):
             rewrite(link, 'src')
-        # BeautifulSoup always stores data in unicode,
-        # but when doing unicode(soup) it does some strange things
-        # like nesting html comments, e.g. returns <!--<!-- comment -->-->
-        # instead of <!-- comment -->.
-        # Converting soup object to string representation first,
-        # and then back to unicode avoids that.
-        # str() called on BeautifulSoup document always returns string
-        # encoded in utf-8, so this should always work.
-        return h.really_unicode(str(soup))
+
+        # html5lib parser adds html/head/body tags, so output <body> without its own tags
+        return unicode(soup.body)[len('<body>'):-len('</body>')]
 
     def _rewrite(self, tag, attr):
         val = tag.get(attr)

http://git-wip-us.apache.org/repos/asf/allura/blob/e0e2f0c4/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index ca04652..91565ae 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -480,6 +480,13 @@ def test_markdown_invalid_tagslash():
     r = g.markdown.convert('<div/onload><img src=x onerror=alert(document.cookie)>')
     assert_not_in('onerror', r)
 
+def test_markdown_invalid_script_in_link():
+    r = g.markdown.convert('[xss](http://"><a onmouseover=prompt(document.domain)>xss</a>)')
+    assert_equal('''<div class="markdown_content"><p><a class="" href='http://"&gt;&lt;a%20onmouseover=prompt(document.domain)&gt;xss&lt;/a&gt;' rel="nofollow">xss</a></p></div>''', r)
+
+def test_markdown_invalid_script_in_link2():
+    r = g.markdown.convert('[xss](http://"><img src=x onerror=alert(document.cookie)>)')
+    assert_equal('''<div class="markdown_content"><p><a class="" href='http://"&gt;&lt;img%20src=x%20onerror=alert(document.cookie)&gt;' rel="nofollow">xss</a></p></div>''', r)
 
 @td.with_wiki
 def test_macro_include():

http://git-wip-us.apache.org/repos/asf/allura/blob/e0e2f0c4/requirements.txt
----------------------------------------------------------------------
diff --git a/requirements.txt b/requirements.txt
index 77581e2..d327584 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,6 @@
 ActivityStream==0.2.0
 BeautifulSoup==3.2.0
+BeautifulSoup4==4.4.0
 Beaker==1.6.4
 chardet==1.0.1
 colander==0.9.3
@@ -81,4 +82,4 @@ q==2.3
 WebError==0.10.3
 -e git://github.com/brondsem/sphinx-argparse.git#egg=sphinx-argparse   # pending merge requests
 sphinx-rtd-theme==0.1.6
-sphinxcontrib-programoutput==0.8
\ No newline at end of file
+sphinxcontrib-programoutput==0.8