diff --git a/src/plugins/keywordNotify/index.tsx b/src/plugins/keywordNotify/index.tsx index 6013b195c..faacbe1a8 100644 --- a/src/plugins/keywordNotify/index.tsx +++ b/src/plugins/keywordNotify/index.tsx @@ -34,6 +34,14 @@ async function addRegex(updater: () => void) { updater(); } +function safeMatchesRegex(s: string, r: string) { + try { + return s.match(new RegExp(r)); + } catch { + return false; + } +} + const settings = definePluginSettings({ replace: { type: OptionType.COMPONENT, @@ -107,7 +115,7 @@ export default definePlugin({ }, applyRegexes(m) { - if (regexes.some(r => r != "" && m.content.match(new RegExp(r)))) { + if (regexes.some(r => r != "" && safeMatchesRegex(m.content, r))) { m.mentions.push(me); } },