Commit cd87d147 by Nathan Shafer Committed by Timothée Peignier

Fixed recursive call to django's staticfiles.finders.find() to prevent…

Fixed recursive call to django's staticfiles.finders.find() to prevent Exceptions on missing files with 3 extensions.
parent 44249c9e
...@@ -46,7 +46,10 @@ class CachedFileFinder(BaseFinder): ...@@ -46,7 +46,10 @@ class CachedFileFinder(BaseFinder):
try: try:
start, _, extn = path.rsplit('.', 2) start, _, extn = path.rsplit('.', 2)
path = '.'.join((start, extn)) path = '.'.join((start, extn))
return find(path, all=all) result = find(path, all=all)
if not result:
return []
return result
except ValueError: except ValueError:
return [] return []
......
from __future__ import unicode_literals from __future__ import unicode_literals
from django.conf import settings
from django.contrib.staticfiles import finders
from django.contrib.staticfiles.storage import staticfiles_storage from django.contrib.staticfiles.storage import staticfiles_storage
from django.core.management import call_command from django.core.management import call_command
from django.test import TestCase from django.test import TestCase
...@@ -69,3 +71,27 @@ class StorageTest(TestCase): ...@@ -69,3 +71,27 @@ class StorageTest(TestCase):
call_command('collectstatic', verbosity=0, interactive=False) call_command('collectstatic', verbosity=0, interactive=False)
except NotImplementedError: except NotImplementedError:
self.fail('Received an error running collectstatic') self.fail('Received an error running collectstatic')
def test_nonexistent_file_pipeline_finder(self):
CUSTOM_FINDERS = settings.STATICFILES_FINDERS + ('pipeline.finders.PipelineFinder',)
with self.settings(STATICFILES_FINDERS=CUSTOM_FINDERS):
path = finders.find('nothing.css')
self.assertIsNone(path)
def test_nonexistent_file_cached_finder(self):
CUSTOM_FINDERS = settings.STATICFILES_FINDERS + ('pipeline.finders.CachedFileFinder',)
with self.settings(STATICFILES_FINDERS=CUSTOM_FINDERS):
path = finders.find('nothing.css')
self.assertIsNone(path)
def test_nonexistent_double_extension_file_pipeline_finder(self):
CUSTOM_FINDERS = settings.STATICFILES_FINDERS + ('pipeline.finders.PipelineFinder',)
with self.settings(STATICFILES_FINDERS=CUSTOM_FINDERS):
path = finders.find('app.css.map')
self.assertIsNone(path)
def test_nonexistent_double_extension_file_cached_finder(self):
CUSTOM_FINDERS = settings.STATICFILES_FINDERS + ('pipeline.finders.CachedFileFinder',)
with self.settings(STATICFILES_FINDERS=CUSTOM_FINDERS):
path = finders.find('app.css.map')
self.assertIsNone(path)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment