[#6812] Fix cached convert UnicodeEncodeError

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@gmail.com>
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 @@
 
         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 @@
 
         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
 
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 @@
         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)