Skip to content

Commit cd87d14

Browse files
Nathan Shafercyberdelia
authored andcommitted
Fixed recursive call to django's staticfiles.finders.find() to prevent Exceptions on missing files with 3 extensions.
1 parent 44249c9 commit cd87d14

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

pipeline/finders.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ def find(self, path, all=False):
4646
try:
4747
start, _, extn = path.rsplit('.', 2)
4848
path = '.'.join((start, extn))
49-
return find(path, all=all)
49+
result = find(path, all=all)
50+
if not result:
51+
return []
52+
return result
5053
except ValueError:
5154
return []
5255

tests/tests/test_storage.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import unicode_literals
22

3+
from django.conf import settings
4+
from django.contrib.staticfiles import finders
35
from django.contrib.staticfiles.storage import staticfiles_storage
46
from django.core.management import call_command
57
from django.test import TestCase
@@ -69,3 +71,27 @@ def test_post_process_no_path(self):
6971
call_command('collectstatic', verbosity=0, interactive=False)
7072
except NotImplementedError:
7173
self.fail('Received an error running collectstatic')
74+
75+
def test_nonexistent_file_pipeline_finder(self):
76+
CUSTOM_FINDERS = settings.STATICFILES_FINDERS + ('pipeline.finders.PipelineFinder',)
77+
with self.settings(STATICFILES_FINDERS=CUSTOM_FINDERS):
78+
path = finders.find('nothing.css')
79+
self.assertIsNone(path)
80+
81+
def test_nonexistent_file_cached_finder(self):
82+
CUSTOM_FINDERS = settings.STATICFILES_FINDERS + ('pipeline.finders.CachedFileFinder',)
83+
with self.settings(STATICFILES_FINDERS=CUSTOM_FINDERS):
84+
path = finders.find('nothing.css')
85+
self.assertIsNone(path)
86+
87+
def test_nonexistent_double_extension_file_pipeline_finder(self):
88+
CUSTOM_FINDERS = settings.STATICFILES_FINDERS + ('pipeline.finders.PipelineFinder',)
89+
with self.settings(STATICFILES_FINDERS=CUSTOM_FINDERS):
90+
path = finders.find('app.css.map')
91+
self.assertIsNone(path)
92+
93+
def test_nonexistent_double_extension_file_cached_finder(self):
94+
CUSTOM_FINDERS = settings.STATICFILES_FINDERS + ('pipeline.finders.CachedFileFinder',)
95+
with self.settings(STATICFILES_FINDERS=CUSTOM_FINDERS):
96+
path = finders.find('app.css.map')
97+
self.assertIsNone(path)

0 commit comments

Comments
 (0)