Validate pattern

729830c2fc443867f1cc83055f2a53711e3763ce

Crow <bismuthglass@protonmail.com>

1 files changed, +8 -2Showing whitespace changes
public/scripts/slash-commands.js+8 -2
@@ -2134,10 +2134,13 @@ export function initDefaultSlashCommands() {
21342134 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
21352135 name: 'test',
21362136 callback: (({ pattern }, text) => {
21372137 if (!pattern === '') {
21382138 throw new Error('Argument of \'pattern=\' cannot be empty');
21392139 }
21402140 let re = regexFromString(pattern.toString());
2141+ if (!re) {
2142+ throw new Error('The value of \'pattern\' argument is not a valid regular expression.');
2143+ }
21412144 return JSON.stringify(re.test(text.toString()));
21422145 }),
21432146 returns: 'true | false',
@@ -2170,10 +2173,13 @@ export function initDefaultSlashCommands() {
21702173 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
21712174 name: 'match',
21722175 callback: (({ pattern }, text) => {
21732176 if (!pattern === '') {
21742177 throw new Error('Argument of \'pattern=\' cannot be empty');
21752178 }
21762179 let re = regexFromString(pattern.toString());
2180+ if (!re) {
2181+ throw new Error('The value of \'pattern\' argument is not a valid regular expression.');
2182+ }
21772183 if (re.flags.includes('g')) {
21782184 return JSON.stringify([...text.toString().matchAll(re)]);
21792185 } else {