Browse Source

Encode minified strings

Rafał Pitoń 10 years ago
parent
commit
63a4897ac9
2 changed files with 21 additions and 2 deletions
  1. 2 1
      misago/markup/parser.py
  2. 19 1
      misago/markup/tests/test_parser.py

+ 2 - 1
misago/markup/parser.py

@@ -151,4 +151,5 @@ def clean_links(result, request):
 
 
 def minify_result(result):
 def minify_result(result):
     # [25:-14] trims <html><head></head><body> and </body></html>
     # [25:-14] trims <html><head></head><body> and </body></html>
-    result['parsed_text'] = html_minify(result['parsed_text'])[25:-14]
+    result['parsed_text'] = html_minify(result['parsed_text'].encode('utf-8'))
+    result['parsed_text'] = result['parsed_text'][25:-14]

+ 19 - 1
misago/markup/tests/test_parser.py

@@ -1,3 +1,6 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
 from django.test import TestCase
 from django.test import TestCase
 
 
 from misago.markup.parser import parse
 from misago.markup.parser import parse
@@ -69,7 +72,7 @@ Dolor met.
 
 
 class MinifyTests(TestCase):
 class MinifyTests(TestCase):
     def test_minified_text(self):
     def test_minified_text(self):
-        """parsed minifies text successfully"""
+        """parser minifies text successfully"""
         test_text = """
         test_text = """
 Lorem ipsum.
 Lorem ipsum.
 
 
@@ -83,6 +86,21 @@ Lorem ipsum.
         result = parse(test_text, MockRequest(), MockPoster(), minify=True)
         result = parse(test_text, MockRequest(), MockPoster(), minify=True)
         self.assertEqual(expected_result, result['parsed_text'])
         self.assertEqual(expected_result, result['parsed_text'])
 
 
+    def test_minified_unicode_text(self):
+        """parser minifies unicode text successfully"""
+        test_text = """
+Bżęczyszczykiewłicz ipsum.
+
+Lorem ipsum.
+""".strip()
+
+        expected_result = """
+<p>Bżęczyszczykiewłicz ipsum.</p><p>Lorem ipsum.</p>
+""".strip()
+
+        result = parse(test_text, MockRequest(), MockPoster(), minify=True)
+        self.assertEqual(expected_result, result['parsed_text'])
+
 
 
 class CleanLinksTests(TestCase):
 class CleanLinksTests(TestCase):
     def test_clean_current_link(self):
     def test_clean_current_link(self):