Skip to content

Commit

Permalink
don't barf on empty style blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed Feb 3, 2015
1 parent 5b8a3dd commit 58f611d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mincss/processor.py
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions tests/one-2.html
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>test page</title>
<style>


</style>
</head>
<body>
<h1>h1</h1>
<h2>h2</h2>
<h3>h3</h3>
</body>
</html>
7 changes: 7 additions & 0 deletions tests/test_mincss.py
Expand Up @@ -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
Expand Down

0 comments on commit 58f611d

Please sign in to comment.