Validate pattern
| @@ -2134,10 +2134,13 @@ export function initDefaultSlashCommands() { | ||
| 2134 | 2134 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 2135 | 2135 | name: 'test', |
| 2136 | 2136 | callback: (({ pattern }, text) => { |
| 2137 | 2137 | if (!pattern === '') { |
| 2138 | 2138 | throw new Error('Argument of \'pattern=\' cannot be empty'); |
| 2139 | 2139 | } |
| 2140 | 2140 | let re = regexFromString(pattern.toString()); |
| 2141 | + if (!re) { | |
| 2142 | + throw new Error('The value of \'pattern\' argument is not a valid regular expression.'); | |
| 2143 | + } | |
| 2141 | 2144 | return JSON.stringify(re.test(text.toString())); |
| 2142 | 2145 | }), |
| 2143 | 2146 | returns: 'true | false', |
| @@ -2170,10 +2173,13 @@ export function initDefaultSlashCommands() { | ||
| 2170 | 2173 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 2171 | 2174 | name: 'match', |
| 2172 | 2175 | callback: (({ pattern }, text) => { |
| 2173 | 2176 | if (!pattern === '') { |
| 2174 | 2177 | throw new Error('Argument of \'pattern=\' cannot be empty'); |
| 2175 | 2178 | } |
| 2176 | 2179 | let re = regexFromString(pattern.toString()); |
| 2180 | + if (!re) { | |
| 2181 | + throw new Error('The value of \'pattern\' argument is not a valid regular expression.'); | |
| 2182 | + } | |
| 2177 | 2183 | if (re.flags.includes('g')) { |
| 2178 | 2184 | return JSON.stringify([...text.toString().matchAll(re)]); |
| 2179 | 2185 | } else { |