Permalink
Browse files

Support cache-busting suffix on asset URLs with querystrings.

  • Loading branch information...
1 parent 11f751d commit 255700c6c3203a64baa2fe487b5f78fce30b4a96 @carljm carljm committed Sep 23, 2012
Showing with 20 additions and 0 deletions.
  1. +2 −0 compressor/filters/css_default.py
  2. +18 −0 compressor/tests/test_filters.py
@@ -52,6 +52,8 @@ def guess_filename(self, url):
local_path = local_path.replace(self.protocol + self.host, "", 1)
# remove url fragment, if any
local_path = local_path.rsplit("#", 1)[0]
+ # remove querystring, if any
+ local_path = local_path.rsplit("?", 1)[0]
# Now, we just need to check if we can find
# the path from COMPRESS_URL in our url
if local_path.startswith(self.url_path):
@@ -142,6 +142,24 @@ def test_css_absolute_filter_url_fragment(self):
output = "p { background: url('%(url)simg/python.png?%(hash)s#foo') }" % params
self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
+ def test_css_absolute_filter_querystring(self):
+ filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
+ imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')
+ params = {
+ 'url': settings.COMPRESS_URL,
+ 'hash': self.hashing_func(imagefilename),
+ }
+ content = "p { background: url('../../img/python.png?foo') }"
+
+ output = "p { background: url('%(url)simg/python.png?foo&%(hash)s') }" % params
+ filter = CssAbsoluteFilter(content)
+ self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
+ settings.COMPRESS_URL = params['url'] = 'http://media.example.com/'
+ filter = CssAbsoluteFilter(content)
+ filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
+ output = "p { background: url('%(url)simg/python.png?foo&%(hash)s') }" % params
+ self.assertEqual(output, filter.input(filename=filename, basename='css/url/test.css'))
+
def test_css_absolute_filter_https(self):
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
imagefilename = os.path.join(settings.COMPRESS_ROOT, 'img/python.png')

0 comments on commit 255700c

Please sign in to comment.