Fix #467: Remove unnecessary checks (filename in COMPRESS_ROOT, or existence of file) in CssAbsoluteFilter
This commit is contained in:
@@ -5,7 +5,6 @@ import posixpath
|
||||
from compressor.cache import get_hashed_mtime, get_hashed_content
|
||||
from compressor.conf import settings
|
||||
from compressor.filters import FilterBase, FilterError
|
||||
from compressor.utils import staticfiles
|
||||
|
||||
URL_PATTERN = re.compile(r'url\(([^\)]+)\)')
|
||||
SRC_PATTERN = re.compile(r'src=([\'"])(.+?)\1')
|
||||
@@ -22,10 +21,7 @@ class CssAbsoluteFilter(FilterBase):
|
||||
self.has_scheme = False
|
||||
|
||||
def input(self, filename=None, basename=None, **kwargs):
|
||||
if filename is not None:
|
||||
filename = os.path.normcase(os.path.abspath(filename))
|
||||
if (not (filename and filename.startswith(self.root)) and
|
||||
not self.find(basename)):
|
||||
if not filename:
|
||||
return self.content
|
||||
self.path = basename.replace(os.sep, '/')
|
||||
self.path = self.path.lstrip('/')
|
||||
@@ -40,10 +36,6 @@ class CssAbsoluteFilter(FilterBase):
|
||||
return SRC_PATTERN.sub(self.src_converter,
|
||||
URL_PATTERN.sub(self.url_converter, self.content))
|
||||
|
||||
def find(self, basename):
|
||||
if settings.DEBUG and basename and staticfiles.finders:
|
||||
return staticfiles.finders.find(basename)
|
||||
|
||||
def guess_filename(self, url):
|
||||
local_path = url
|
||||
if self.has_scheme:
|
||||
|
||||
@@ -216,6 +216,21 @@ class CssAbsolutizingTestCase(TestCase):
|
||||
filter = CssAbsoluteFilter(content)
|
||||
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
|
||||
|
||||
def test_css_absolute_filter_filename_outside_compress_root(self):
|
||||
filename = '/foo/bar/baz/test.css'
|
||||
content = self.template % blankdict(url='../qux/')
|
||||
params = blankdict({
|
||||
'url': settings.COMPRESS_URL + 'bar/qux/',
|
||||
})
|
||||
output = self.template % params
|
||||
filter = CssAbsoluteFilter(content)
|
||||
self.assertEqual(output, filter.input(filename=filename, basename='bar/baz/test.css'))
|
||||
settings.COMPRESS_URL = 'https://static.example.com/'
|
||||
params['url'] = settings.COMPRESS_URL + 'bar/qux/'
|
||||
output = self.template % params
|
||||
filter = CssAbsoluteFilter(content)
|
||||
self.assertEqual(output, filter.input(filename=filename, basename='bar/baz/test.css'))
|
||||
|
||||
def test_css_hunks(self):
|
||||
hash_dict = {
|
||||
'hash1': self.hashing_func(os.path.join(settings.COMPRESS_ROOT, 'img/python.png')),
|
||||
|
||||
Reference in New Issue
Block a user