Skip to content

Commit

Permalink
Encode compiled content when writing it w/o compression
Browse files Browse the repository at this point in the history
As of django-compressor#312, the output of compiled content is always unicode.

With ``COMPRESS_ENABLED=True``,
that unicode was piped directly to compression
without writing the intermediate content.
The byte encoding of the compressed content
is handled correctly in this case.

However, with ``COMPRESS_ENABLED=False``,
the unicode content was sent directly to a
``django.core.files.base.ContentFile`` instance,
and somewhere in there
it turned that content into 4-byte-wide characters
resembling UTF-32 encoded content.

This encodes that content using UTF-8
before handing it off to the ``ContentFile``.

This may present an issue in a corner case
where something other than UTF-8 encoding is desired.

Signed-off-by: Liam Curry <liam@curry.name>
  • Loading branch information
matthewryanscott authored and Liam Curry committed Apr 30, 2013
1 parent fe78891 commit 4976392
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion compressor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def output_file(self, mode, content, forced=False, basename=None):
"""
new_filepath = self.get_filepath(content, basename=basename)
if not self.storage.exists(new_filepath) or forced:
self.storage.save(new_filepath, ContentFile(content))
self.storage.save(new_filepath, ContentFile(content.encode('utf8')))
url = mark_safe(self.storage.url(new_filepath))
return self.render_output(mode, {"url": url})

Expand Down

0 comments on commit 4976392

Please sign in to comment.