Skip to content

Commit 3ad29d1

Browse files
committed
Fix panic when selector ends with '('.
Found with go-fuzz.
1 parent 893e27f commit 3ad29d1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

parser.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ func (p *parser) parseAttributeSelector() (Selector, error) {
414414

415415
var expectedParenthesis = errors.New("expected '(' but didn't find it")
416416
var expectedClosingParenthesis = errors.New("expected ')' but didn't find it")
417+
var unmatchedParenthesis = errors.New("unmatched '('")
417418

418419
// parsePseudoclassSelector parses a pseudoclass selector like :not(p).
419420
func (p *parser) parsePseudoclassSelector() (Selector, error) {
@@ -457,6 +458,9 @@ func (p *parser) parsePseudoclassSelector() (Selector, error) {
457458
if !p.consumeParenthesis() {
458459
return nil, expectedParenthesis
459460
}
461+
if p.i == len(p.s) {
462+
return nil, unmatchedParenthesis
463+
}
460464
var val string
461465
switch p.s[p.i] {
462466
case '\'', '"':

0 commit comments

Comments
 (0)