Commit 785e62a4 authored by Bob's avatar Bob Committed by Johannes Linke

silently ignore link tags if missing rel atrribute (#812)

parent f7886c06
......@@ -16,7 +16,7 @@ class CssCompressor(Compressor):
data = None
elem_name = self.parser.elem_name(elem)
elem_attribs = self.parser.elem_attribs(elem)
if elem_name == 'link' and elem_attribs['rel'].lower() == 'stylesheet':
if elem_name == 'link' and 'rel' in elem_attribs and elem_attribs['rel'].lower() == 'stylesheet':
basename = self.get_basename(elem_attribs['href'])
filename = self.get_filename(basename)
data = (SOURCE_FILE, filename, basename, elem)
......
......@@ -44,6 +44,23 @@ class TemplatetagTestCase(TestCase):
<link rel="stylesheet" href="{{ STATIC_URL }}css/one.css" type="text/css">
<style type="text/css">p { border:5px solid green;}</style>
<link rel="stylesheet" href="{{ STATIC_URL }}css/two.css" type="text/css">
{% endcompress %}"""
out = css_tag("/static/CACHE/css/e41ba2cc6982.css")
self.assertEqual(out, render(template, self.context))
def test_missing_rel_leaves_empty_result(self):
template = """{% load compress %}{% compress css %}
<link href="{{ STATIC_URL }}css/one.css" type="text/css">
{% endcompress %}"""
out = ""
self.assertEqual(out, render(template, self.context))
def test_missing_rel_only_on_one_resource(self):
template = """{% load compress %}{% compress css %}
<link href="{{ STATIC_URL }}css/wontmatter.css" type="text/css">
<link rel="stylesheet" href="{{ STATIC_URL }}css/one.css" type="text/css">
<style type="text/css">p { border:5px solid green;}</style>
<link rel="stylesheet" href="{{ STATIC_URL }}css/two.css" type="text/css">
{% endcompress %}"""
out = css_tag("/static/CACHE/css/e41ba2cc6982.css")
self.assertEqual(out, render(template, self.context))
......
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