Skip to content

Commit

Permalink
special application of the "i" flag in user regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
Supinic committed Apr 6, 2024
1 parent 7eb46ed commit f858d9d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion classes/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -1057,8 +1057,18 @@ class Command extends require("./template.js") {
if (process.execArgv.includes(LINEAR_REGEX_FLAG)) {
let linearRegex;
try {
let source = regex.source;
let flags = regex.flags;

// Since the "i" flag makes the regex not execute in linear time, use a hacky solution to
// replace all characters with a group that contains both cases. Then, also remove the "i" flag.
if (regex.flags.includes("i")) {
source = source.replaceAll(/(?<!\\)([a-z])/ig, (total, match) => `[${match.toLowerCase()}${match.toUpperCase()}]`);
flags = flags.replace("i", "");
}

// Force the "linear" regex flag
linearRegex = new RegExp(regex.source, `${regex.flags}l`);
linearRegex = new RegExp(source, `${flags}l`);
}
catch {
return null;
Expand Down

0 comments on commit f858d9d

Please sign in to comment.