• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

allura


コミットメタ情報

リビジョンa490e18e37df8ccc60eb566731d82e4d2ebf937a (tree)
日時2012-01-25 14:38:25
作者Dave Brondsema <dbrondsema@geek...>
コミッターDave Brondsema

ログメッセージ

[#3643] make readme rendering of plaintext safe

Signed-off-by: Dave Brondsema <dbrondsema@geek.net>

変更サマリ

差分

--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -25,6 +25,7 @@ from pylons import c, response, request
2525 from tg.decorators import before_validate
2626 from formencode.variabledecode import variable_decode
2727 import formencode
28+from jinja2 import Markup
2829
2930 from webhelpers import date, feedgenerator, html, number, misc, text
3031
@@ -541,12 +542,14 @@ def paging_sanitizer(limit, page, total_count, zero_based_pages=True):
541542 return limit, page
542543
543544 def render_any_markup(name, text):
545+ """
546+ renders any markup format using the pypeline
547+ Returns jinja-safe text
548+ """
544549 if text == '':
545550 text = '<p><em>Empty File</em></p>'
546551 else:
547- renderer = pylons.g.pypeline_markup.renderer(name)
548- if renderer[1]:
549- text = pylons.g.pypeline_markup.render(name,text)
550- else:
552+ text = pylons.g.pypeline_markup.render(name, text)
553+ if not pylons.g.pypeline_markup.can_render(name):
551554 text = '<pre>%s</pre>' % text
552- return text
\ No newline at end of file
555+ return Markup(text)
\ No newline at end of file
--- a/Allura/allura/templates/repo/tree.html
+++ b/Allura/allura/templates/repo/tree.html
@@ -27,6 +27,6 @@ Tree <a href="{{commit.url()}}">{{commit.shorthand_id()}}</a> {{commit_labels(co
2727 {% set name, text = tree.readme() %}
2828 {% if name %}
2929 <h1 id="readme">Read Me</h1>
30- {{h.render_any_markup(name, text)|safe}}
30+ {{h.render_any_markup(name, text)}}
3131 {% endif %}
3232 {% endblock %}
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -114,5 +114,14 @@ def test_paging_sanitizer():
114114 for input, output in test_data.iteritems():
115115 assert (h.paging_sanitizer(*input)) == output
116116
117-def test_render_any_markup():
118- pass
\ No newline at end of file
117+def test_render_any_markup_empty():
118+ assert_equals(h.render_any_markup('foo', ''), '<p><em>Empty File</em></p>')
119+
120+def test_render_any_markup_plain():
121+ assert_equals(h.render_any_markup('readme.txt', '<b>blah</b>\n<script>alert(1)</script>\nfoo'),
122+ '<pre>&lt;b&gt;blah&lt;/b&gt;\n&lt;script&gt;alert(1)&lt;/script&gt;\nfoo</pre>')
123+
124+def test_render_any_markup_formatting():
125+ assert_equals(h.render_any_markup('README.md', '### foo\n<script>alert(1)</script> bar'),
126+ '<h3>foo</h3>\n<p>&lt;script&gt;alert(1)&lt;/script&gt; bar</p>')
127+