Skip to content

Commit e44fc8b

Browse files
committed
🐛 fix crash on invalid filters (fixes #37)
1 parent b599764 commit e44fc8b

File tree

5 files changed

+1077
-1
lines changed

5 files changed

+1077
-1
lines changed

src/script/index.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,32 @@ function parseFilter(
485485
parserOptions,
486486
)
487487
const statement = ast.body[0] as ESLintExpressionStatement
488-
const callExpression = statement.expression as ESLintCallExpression
488+
const callExpression = statement.expression
489489

490490
ast.tokens!.shift()
491491

492+
if (
493+
callExpression.type !== "CallExpression" ||
494+
callExpression.callee.type !== "Literal"
495+
) {
496+
// Report the next token of `)`.
497+
let nestCount = 1
498+
for (const token of ast.tokens!.slice(1)) {
499+
if (nestCount === 0) {
500+
return throwUnexpectedTokenError(token.value, token)
501+
}
502+
if (token.type === "Punctuator" && token.value === "(") {
503+
nestCount += 1
504+
}
505+
if (token.type === "Punctuator" && token.value === ")") {
506+
nestCount -= 1
507+
}
508+
}
509+
510+
const token = last(ast.tokens)!
511+
return throwUnexpectedTokenError(token.value, token)
512+
}
513+
492514
for (const argument of callExpression.arguments) {
493515
argument.parent = expression
494516
expression.arguments.push(argument)

0 commit comments

Comments
 (0)