mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-21 08:45:03 +00:00
Fixes to RegExpRunner usage in !search and !bansearch, validate that input regex is valid
This commit is contained in:
parent
917b2d25a5
commit
91305d2941
3 changed files with 94 additions and 15 deletions
|
@ -7,13 +7,19 @@ import safeRegex from "safe-regex";
|
|||
|
||||
const regexWithFlags = /^\/(.*?)\/([i]*)$/;
|
||||
|
||||
export class InvalidRegexError extends Error {}
|
||||
|
||||
/**
|
||||
* This function supports two input syntaxes for regexes: /<pattern>/<flags> and just <pattern>
|
||||
*/
|
||||
export function inputPatternToRegExp(pattern: string) {
|
||||
const advancedSyntaxMatch = pattern.match(regexWithFlags);
|
||||
const [finalPattern, flags] = advancedSyntaxMatch ? [advancedSyntaxMatch[1], advancedSyntaxMatch[2]] : [pattern, ""];
|
||||
return new RegExp(finalPattern, flags);
|
||||
try {
|
||||
return new RegExp(finalPattern, flags);
|
||||
} catch (e) {
|
||||
throw new InvalidRegexError(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
export const TRegex = new t.Type<RegExp, string>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue