Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cssutils/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,10 @@ def do_CSSUnknownRule(self, rule):
for item in rule.seq:
type_, val = item.type, item.value
# PRE
if '}' == val:
# close last open item on stack
if '}' == val and stacks:
# close last open item on stack (a "}" with no matching
# "{" leaves the stack empty; fall through and emit it as a
# plain token instead of popping from an empty list)
stackblock = stacks.pop().value()
if stackblock:
val = self._indentblock(
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cssunknownrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ def test_init(self):
assert '@init xxx {\n yyy\n }' == r.cssText
assert r.wellformed

def test_serialize_unmatched_closing_brace(self):
"CSSUnknownRule serialization with a '}' that has no matching '{'"
# Serializing such a rule used to raise IndexError (pop from empty
# list) while walking the brace stack.
sheet = cssutils.parseString('@keyframes k { 0% { opacity: 0; }"}')
# must not raise
assert isinstance(sheet.cssText, bytes)

def test_cssText(self):
"CSSUnknownRule.cssText"
tests = {
Expand Down