Skip to content

Commit

Permalink
fix: regex complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
vadson71 committed Jan 9, 2024
1 parent 83408ba commit 220c63d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/binding-parser/src/lexer/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,23 @@ const whiteSpace = createToken({
// group: Lexer.SKIPPED,
line_breaks: true,
});

const specChars = "#!\"'$%&()*+-./;<=>?@\\^_`~|";
const charsToEscape = "$()*+./?^|\\";

const tokens: string[] = specChars.split("").map((token) => {
if (charsToEscape.includes(token)) {
token = "\\" + token;
}
return token;
});

const regExLookup = [...tokens, "&gt;", "&#47;", "&#x2F;"].join("|");
const pattern = new RegExp(`/(?:${regExLookup})+/`);

const specialChars = createToken({
name: SPECIAL_CHARS,
pattern:
/(?:#|&gt;|&#47;|&#x2F;|!|"|\$|%|&|'|\(|\)|\*|\+|-|\.|\/|;|<|=|>|\?|@|\\|\^|_|`|~|\|)+/,
pattern,
});

const leftCurly = createToken({
Expand Down

0 comments on commit 220c63d

Please sign in to comment.