fix cached precompiler for unicode input

This commit is contained in:
Johannes Linke
2015-09-06 13:11:14 +02:00
parent 9c2e06d377
commit 7b1e442832
3 changed files with 9 additions and 3 deletions

View File

@@ -136,7 +136,7 @@ def get_hashed_content(filename, length=12):
def get_precompiler_cachekey(command, contents):
return hashlib.sha1('precompiler.%s.%s' % (command, contents)).hexdigest()
return hashlib.sha1(smart_bytes('precompiler.%s.%s' % (command, contents))).hexdigest()
def cache_get(key):

View File

@@ -233,4 +233,4 @@ class CachedCompilerFilter(CompilerFilter):
return super(CachedCompilerFilter, self).input(**kwargs)
def get_cache_key(self):
return get_precompiler_cachekey(self.command, self.content.encode('utf8'))
return get_precompiler_cachekey(self.command, self.content)

View File

@@ -14,7 +14,7 @@ from django.test.utils import override_settings
from compressor import cache as cachemod
from compressor.base import SOURCE_FILE, SOURCE_HUNK
from compressor.cache import get_cachekey
from compressor.cache import get_cachekey, get_precompiler_cachekey
from compressor.conf import settings
from compressor.css import CssCompressor
from compressor.exceptions import FilterDoesNotExist, FilterError
@@ -331,3 +331,9 @@ class CacheTestCase(SimpleTestCase):
@override_settings(COMPRESS_CACHE_KEY_FUNCTION='invalid.module')
def test_get_cachekey_invalid_mod(self):
self.assertRaises(ImportError, lambda: get_cachekey("foo"))
def test_get_precompiler_cachekey(self):
try:
get_precompiler_cachekey("asdf", "asdf")
except TypeError:
self.fail("get_precompiler_cachekey raised TypeError unexpectedly")