Code

#18430 closed Bug (fixed)

CachedFilesMixin crashed when CSS files contains non-ascii utf-8 character

Reported by: brantyoung Owned by: dbrgn
Component: contrib.staticfiles Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Traceback (most recent call last):

...
...
  File ".../ENV/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 120, in collect
    for original_path, processed_path, processed in processor:
  File ".../ENV/local/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 226, in post_process
    content = pattern.sub(converter, content)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 366: ordinal not in range(128)

Reproduce:

# save a css file that contains non-ascii utf-8 character (ie Chinese character):

.icon-link:before { content: "错"; }

# set STATICFILES_STORAGE to any storage class that will involve CachedFilesMixin mixin
# run manage.py collectstatic

Howto fix:

I relace following code:

content = original_file.read().decode

to:

content = original_file.read().decode('utf-8')

just worked as expected.

Attachments (0)

Change History (5)

comment:1 Changed 23 months ago by dbrgn

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to dbrgn
  • Patch needs improvement unset

comment:2 Changed 23 months ago by dbrgn

  • Severity changed from Release blocker to Normal

I can't reproduce this on current trunk using STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.CachedStaticFilesStorage' (which uses the CachedFilesMixin). I even tried converting the css file to latin1, which garbled the contents, but still worked using collectstatic.

Could you provide a CSS file that causes problems for you?

Or can somebody else reproduce the problem?

comment:3 Changed 23 months ago by aaugustin

  • Resolution set to needsinfo
  • Status changed from new to closed

Closing as 'needsinfo' since there isn't enough information to reproduce the issue.

Last edited 23 months ago by aaugustin (previous) (diff)

comment:4 Changed 23 months ago by brantyoung

  • Resolution needsinfo deleted
  • Status changed from closed to reopened

I create a minimal project to reproduce this ticket: https://bitbucket.org/brantyoung/cached_files_mixin_bug/

It's weird, if I moving all of font files to any directory except *PROJECTROOT*/css, every thing works fine.

But if both iconic-font.css and font files in the same sub-directory, CachedFilesMixin will crash.

Last edited 23 months ago by brantyoung (previous) (diff)

comment:5 Changed 22 months ago by Jannis Leidel <jannis@…>

  • Resolution set to fixed
  • Status changed from reopened to closed

In [3727f6d09681e4cb23d67e14ecc677a364c991bd]:

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.