allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [13/27] git commit: [#6812] Fix cached convert UnicodeEncodeError
Date Thu, 31 Oct 2013 18:41:28 GMT
[#6812] Fix cached convert UnicodeEncodeError

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@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/7907fb98
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/7907fb98
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/7907fb98

Branch: refs/heads/cj/6692
Commit: 7907fb9863ecca8d5543cbaa6ffda0f7ce053cff
Parents: ccf83fb
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Wed Oct 30 16:36:33 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Wed Oct 30 16:36:33 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/app_globals.py    | 4 ++--
 Allura/allura/tests/test_globals.py | 9 +++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7907fb98/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 14fa5a1..2ea8163 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -97,7 +97,7 @@ class ForgeMarkdown(markdown.Markdown):
 
         md5 = None
         if cache.md5 is not None:
-            md5 = hashlib.md5(source_text).hexdigest()
+            md5 = hashlib.md5(source_text.encode('utf-8')).hexdigest()
             if cache.md5 == md5:
                 return cache.html
 
@@ -115,7 +115,7 @@ class ForgeMarkdown(markdown.Markdown):
 
         if threshold != None and render_time > threshold:
             if md5 is None:
-                md5 = hashlib.md5(source_text).hexdigest()
+                md5 = hashlib.md5(source_text.encode('utf-8')).hexdigest()
             cache.md5, cache.html, cache.render_time = md5, html, render_time
         return html
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7907fb98/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index a1e8e55..c11c8d3 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -563,6 +563,15 @@ class TestCachedMarkdown(unittest.TestCase):
         self.assertEqual(html, self.expected_html)
 
     @patch.dict('allura.lib.app_globals.config', markdown_cache_threshold='0')
+    def test_non_ascii(self):
+        self.post.text = u'å∫ç'
+        expected = u'<p>å∫ç</p>'
+        # test with empty cache
+        self.assertEqual(expected, self.md.cached_convert(self.post, 'text'))
+        # test with primed cache
+        self.assertEqual(expected, self.md.cached_convert(self.post, 'text'))
+
+    @patch.dict('allura.lib.app_globals.config', markdown_cache_threshold='0')
     def test_empty_cache(self):
         html = self.md.cached_convert(self.post, 'text')
         self.assertEqual(html, self.expected_html)


Mime
View raw message