Opened 4 years ago

Closed 4 years ago

#26671 closed Bug (fixed)

`ManifestStaticFilesStorage` does not work for CSS with URLs including `chrome` scheme

Reported by: Tai Lee Owned by: Deepak Sattiraju
Component: contrib.staticfiles Version: master
Severity: Normal Keywords: ManifestStaticFilesStorage chrome scheme
Cc: dsattiraju249@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

One of the 3rd party CSS files used by our project contains CSS like this:

.sourceRow[exe_line="true"] > .sourceLine {
    background-image: url(chrome://firebug/skin/exe.png);
    color: #000000;
}

This causes ManifestStaticFilesStorage to crash with:

Post-processing 'lodash/vendor/firebug-lite/skin/xp/debugger.css' failed!
Traceback (most recent call last):
  File "./manage.py", line 23, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle
    collected = self.collect()
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 120, in collect
    raise processed
ValueError: The file 'lodash/vendor/firebug-lite/skin/xp/chrome:/firebug/skin/exe.png' could not be found with <django.contrib.staticfiles.storage.ManifestStaticFilesStorage object at 0x7faab0f72950>.

Looks like this .startswith() call needs to change to a regex, or at least include a few more known schemes:

https://github.com/django/django/blob/edcecaf0dea718a8fb216df478df0d151a9ba04d/django/contrib/staticfiles/storage.py#L166

            if url.startswith(('http:', 'https:', '//', '#', 'data:')):
                return matched

Something like this should do the trick (very briefly tested in interactive shell):

            if re.match(r'(?i)([a-z]+://|//|#|data:)', url):
                return matched

Change History (6)

comment:1 Changed 4 years ago by Tim Graham

Component: Core (Management commands)contrib.staticfiles
Triage Stage: UnreviewedAccepted

comment:2 Changed 4 years ago by Simon Charette

Has patch: set
Needs tests: set
Patch needs improvement: set
Version: 1.9master
Last edited 4 years ago by Deepak Sattiraju (previous) (diff)

comment:3 Changed 4 years ago by Deepak Sattiraju

Cc: dsattiraju249@… added
Owner: changed from nobody to Deepak Sattiraju
Status: newassigned

comment:4 Changed 4 years ago by Tim Graham

Needs tests: unset

Updated PR with a few comments for improvement.

comment:5 Changed 4 years ago by Tim Graham

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:6 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 08ed3cc6:

Fixed #26671 -- Made HashedFilesMixin ignore the 'chrome' scheme.

Note: See TracTickets for help on using tickets.
Back to Top