Skip to content
Merged
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 css/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ func (p *Parser) parseAtRuleUnknown() GrammarType {
}
if p.tt == LeftParenthesisToken || p.tt == LeftBraceToken || p.tt == LeftBracketToken || p.tt == FunctionToken {
p.level++
} else if p.tt == RightParenthesisToken || p.tt == RightBraceToken || p.tt == RightBracketToken {
} else if (p.tt == RightParenthesisToken || p.tt == RightBraceToken || p.tt == RightBracketToken) && 0 < p.level {
// a closing token without its opening one is not a level
p.level--
}
return TokenGrammar
Expand Down Expand Up @@ -490,7 +491,8 @@ func (p *Parser) parseDeclarationError(tt TokenType, data []byte) GrammarType {
return ErrorGrammar
} else if tt == LeftParenthesisToken || tt == LeftBraceToken || tt == LeftBracketToken || tt == FunctionToken {
p.level++
} else if tt == RightParenthesisToken || tt == RightBraceToken || tt == RightBracketToken {
} else if (tt == RightParenthesisToken || tt == RightBraceToken || tt == RightBracketToken) && 0 < p.level {
// a closing token without its opening one (the offending token of the error) is not a level
p.level--
}

Expand Down
4 changes: 4 additions & 0 deletions css/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func TestParse(t *testing.T) {
{false, ".foo { visibility: hidden;” } .bar { color:red; }", ".foo{visibility:hidden;ERROR(expected colon in declaration)}.bar{color:red;}"},
{false, ".foo { baddecl (; color:red; }", ".foo{ERROR(expected colon in declaration)"},
{true, "color=blue;", "ERROR(expected colon in declaration)"},
{true, "color:red);display:none", "ERROR(unexpected ending in declaration)display:none;"},
{true, "color:red];display:none", "ERROR(unexpected ending in declaration)display:none;"},
{false, ".foo { color:red); display:none } .bar { color:red; }", ".foo{ERROR(unexpected ending in declaration)display:none;}.bar{color:red;}"},
{false, "@foo { a) } .bar { color:red; }", "@foo{a) }.bar{color:red;}"},

// issues
{false, "@media print {.class{width:5px;}}", "@media print{.class{width:5px;}}"}, // #6
Expand Down