From 3727f6d09681e4cb23d67e14ecc677a364c991bd Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 8 Jul 2012 12:56:49 +0200 Subject: [PATCH] Fixed #18430 -- Use the FILE_CHARSET setting when reading from a file during post processing with the cached staticfiles storage. Thanks to Brant Young for initial debugging. --- django/contrib/staticfiles/storage.py | 2 +- .../apps/test/static/test/nonascii.css | 5 +++++ .../apps/test/static/test/window.png | Bin 0 -> 207 bytes tests/regressiontests/staticfiles_tests/tests.py | 5 +++-- 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 tests/regressiontests/staticfiles_tests/apps/test/static/test/nonascii.css create mode 100644 tests/regressiontests/staticfiles_tests/apps/test/static/test/window.png diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py index e02fec8ec0..16d33fff4b 100644 --- a/django/contrib/staticfiles/storage.py +++ b/django/contrib/staticfiles/storage.py @@ -228,7 +228,7 @@ class CachedFilesMixin(object): # ..to apply each replacement pattern to the content if name in adjustable_paths: - content = original_file.read() + content = original_file.read().decode(settings.FILE_CHARSET) converter = self.url_converter(name) for patterns in self._patterns.values(): for pattern in patterns: diff --git a/tests/regressiontests/staticfiles_tests/apps/test/static/test/nonascii.css b/tests/regressiontests/staticfiles_tests/apps/test/static/test/nonascii.css new file mode 100644 index 0000000000..a5358f6ede --- /dev/null +++ b/tests/regressiontests/staticfiles_tests/apps/test/static/test/nonascii.css @@ -0,0 +1,5 @@ +body { + background: url('window.png'); +} + +.snowman:before { content: "☃"; } diff --git a/tests/regressiontests/staticfiles_tests/apps/test/static/test/window.png b/tests/regressiontests/staticfiles_tests/apps/test/static/test/window.png new file mode 100644 index 0000000000000000000000000000000000000000..ba48325c0a580d4480cb9f76713d5ec9b2c3756a GIT binary patch literal 207 zcmeAS@N?(olHy`uVBq!ia0vp^q9Dw{1|(OCFP#RYrg^$JhFF|FdNr5tfB+A}g?R_~ z{oaP`=$u`mn5ncc$|Q1f>cKq*B1@)RuxwXksp*wS-nu}?4ww>;!tZUL%?Z@*`pWolf$81WoeO<{E@bd@^>bP0 Hl+XkKUAs`5 literal 0 HcmV?d00001 diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py index 7678d7f100..91435a2c86 100644 --- a/tests/regressiontests/staticfiles_tests/tests.py +++ b/tests/regressiontests/staticfiles_tests/tests.py @@ -498,8 +498,9 @@ class TestCollectionCachedStorage(BaseCollectionTestCase, collectstatic_cmd = CollectstaticCommand() collectstatic_cmd.set_options(**collectstatic_args) stats = collectstatic_cmd.collect() - self.assertTrue(os.path.join('cached', 'css', 'window.css') in stats['post_processed']) - self.assertTrue(os.path.join('cached', 'css', 'img', 'window.png') in stats['unmodified']) + self.assertIn(os.path.join('cached', 'css', 'window.css'), stats['post_processed']) + self.assertIn(os.path.join('cached', 'css', 'img', 'window.png'), stats['unmodified']) + self.assertIn(os.path.join('test', 'nonascii.css'), stats['post_processed']) def test_cache_key_memcache_validation(self): """