Skip to content

Commit

Permalink
Leave alone fragment-only URLs.
Browse files Browse the repository at this point in the history
Without this change, mangling such URLs produces invalid results.
  • Loading branch information
jscheid committed Feb 3, 2013
1 parent 1a7f1ff commit 8254f8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compressor/filters/css_default.py
Expand Up @@ -91,7 +91,9 @@ def add_suffix(self, url):
def _converter(self, matchobj, group, template):
url = matchobj.group(group)
url = url.strip(' \'"')
if url.startswith(SCHEMES):
if url.startswith('#'):
return "url('%s')" % url
elif url.startswith(SCHEMES):
return "url('%s')" % self.add_suffix(url)
full_url = posixpath.normpath('/'.join([str(self.directory_name),
url]))
Expand Down
10 changes: 10 additions & 0 deletions compressor/tests/test_filters.py
Expand Up @@ -142,6 +142,16 @@ 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_only_url_fragment(self):
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
content = "p { background: url('#foo') }"
filter = CssAbsoluteFilter(content)
self.assertEqual(content, filter.input(filename=filename, basename='css/url/test.css'))
settings.COMPRESS_URL = 'http://media.example.com/'
filter = CssAbsoluteFilter(content)
filename = os.path.join(settings.COMPRESS_ROOT, 'css/url/test.css')
self.assertEqual(content, 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')
Expand Down

0 comments on commit 8254f8d

Please sign in to comment.