allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [16/50] git commit: [#5607] ticket:319 Render text as plain text if it's too big
Date Fri, 03 May 2013 21:57:46 GMT
[#5607] ticket:319 Render text as plain text if it's too big


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

Branch: refs/heads/db/6007
Commit: 4510805ac0c6fe8594cb220850dd0efe2cc50e4c
Parents: ed4a5a0
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu Apr 25 10:49:20 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Mon Apr 29 21:59:43 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/app_globals.py    |    7 +++++++
 Allura/allura/tests/test_globals.py |    8 ++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4510805a/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index e5b00c7..a8d2006 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -60,9 +60,16 @@ from allura.lib.zarkov_helpers import ZarkovClient, zmq
 
 log = logging.getLogger(__name__)
 
+BIG_TEXT_THRESHOLD = 90000
+
 
 class ForgeMarkdown(markdown.Markdown):
     def convert(self, source):
+        if len(source) > BIG_TEXT_THRESHOLD:
+            # if text is too big, markdown can take a long time to process it, so we return
it as a plain text
+            log.info('Text is too big. Skipping markdown processing')
+            escaped = cgi.escape(h.really_unicode(source))
+            return h.html.literal(u'<pre>%s</pre>' % escaped)
         try:
             return markdown.Markdown.convert(self, source)
         except Exception:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4510805a/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index ea7fc1d..ccf90cc 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -283,6 +283,14 @@ def test_markdown_within_html():
 </div>''' in r, r
 
 
+def test_markdown_big_text():
+    '''If text is too big g.markdown.convert should return plain text'''
+    from allura.lib.app_globals import BIG_TEXT_THRESHOLD
+    text = 'a' * (BIG_TEXT_THRESHOLD + 1)
+    assert_equal(g.markdown.convert(text), '<pre>%s</pre>' % text)
+    assert_equal(g.markdown_wiki.convert(text), '<pre>%s</pre>' % text)
+
+
 @td.with_wiki
 def test_markdown_basics():
     with h.push_context('test', 'wiki', neighborhood='Projects'):


Mime
View raw message