Merge pull request #271 from midiotthimble/develop
Fixes UnicodeDecodeError with inline css or javascript (closes #270)
This commit is contained in:
@@ -108,7 +108,7 @@ class CompressorMixin(object):
|
||||
rendered_output = self.render_output(compressor, mode, forced=forced)
|
||||
if cache_key:
|
||||
cache_set(cache_key, rendered_output)
|
||||
return rendered_output
|
||||
return rendered_output.decode('utf-8')
|
||||
except Exception:
|
||||
if settings.DEBUG or forced:
|
||||
raise
|
||||
|
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import with_statement
|
||||
|
||||
from django.test import TestCase
|
||||
@@ -123,3 +124,15 @@ class TestJinja2CompressorExtension(TestCase):
|
||||
context = {'MEDIA_URL': settings.COMPRESS_URL}
|
||||
out = '<script type="text/javascript">obj={};obj.value="value";</script>'
|
||||
self.assertEqual(out, template.render(context))
|
||||
|
||||
def test_nonascii_inline_css(self):
|
||||
org_COMPRESS_ENABLED = settings.COMPRESS_ENABLED
|
||||
settings.COMPRESS_ENABLED = False
|
||||
template = self.env.from_string(u'{% compress css %}'
|
||||
u'<style type="text/css">'
|
||||
u'/* русский текст */'
|
||||
u'</style>{% endcompress %}')
|
||||
out = u'<link rel="stylesheet" href="/media/CACHE/css/b2cec0f8cb24.css" type="text/css" />'
|
||||
settings.COMPRESS_ENABLED = org_COMPRESS_ENABLED
|
||||
context = {'MEDIA_URL': settings.COMPRESS_URL}
|
||||
self.assertEqual(out, template.render(context))
|
||||
|
Reference in New Issue
Block a user