diff --git a/mincss/processor.py b/mincss/processor.py index e2c3c73..3026262 100644 --- a/mincss/processor.py +++ b/mincss/processor.py @@ -190,7 +190,11 @@ def process_html(self, html, url): self._all_classes.add(class_) for style in CSSSelector('style')(page): - first_line = style.text.strip().splitlines()[0] + try: + first_line = style.text.strip().splitlines()[0] + except IndexError: + # meaning the inline style tag was just whitespace + continue for i, line in enumerate(lines): if line.count(first_line): key = (i + 1, url) diff --git a/tests/one-2.html b/tests/one-2.html new file mode 100644 index 0000000..d46b244 --- /dev/null +++ b/tests/one-2.html @@ -0,0 +1,16 @@ + + + + + test page + + + +

h1

+

h2

+

h3

+ + diff --git a/tests/test_mincss.py b/tests/test_mincss.py index 936ea1d..adaeed5 100644 --- a/tests/test_mincss.py +++ b/tests/test_mincss.py @@ -42,6 +42,13 @@ def test_just_inline(self): for i, line in enumerate(expect.strip().splitlines()): eq_(line.strip(), lines_after[i].strip()) + def test_html_with_empty_style_tag(self): + html = os.path.join(HERE, 'one-2.html') + url = 'file://' + html + p = Processor() + p.process(url) + eq_(p.inlines, []) + def test_just_one_link(self): html = os.path.join(HERE, 'two.html') url = 'file://' + html