Skip to content

Commit

Permalink
Merge pull request #500 from iorate/fix-crash-on-invalid-rules
Browse files Browse the repository at this point in the history
fix(ruleset): fix crash on invalid rules
  • Loading branch information
iorate committed Jun 23, 2024
2 parents d2b28a0 + d4d79d2 commit c8e33c1
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/scripts/ruleset/ruleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,18 @@ function collectRuleset(
// An invalid string literal or regular expression
continue;
}
rules.set(
matchPattern ?? "<all_urls>",
expression
? [lineNumber, value, expression]
: value !== 1
? [lineNumber, value]
: [lineNumber],
);
try {
rules.set(
matchPattern ?? "<all_urls>",
expression
? [lineNumber, value, expression]
: value !== 1
? [lineNumber, value]
: [lineNumber],
);
} catch {
// #497 Just in case
}
}
}

Expand All @@ -220,7 +224,8 @@ function hasError(ruleNode: SyntaxNode): boolean {
if (cursor.type.isError) {
return true;
}
} while (cursor.next() && cursor.to <= ruleNode.to);
// #497 An error node may expand to the next line
} while (cursor.next() && cursor.from <= ruleNode.to + 1);
return false;
}

Expand Down

0 comments on commit c8e33c1

Please sign in to comment.