From 808c664d9357033e769c75754edb149ac299ec8d Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Sun, 19 Nov 2023 18:25:11 -0600 Subject: [PATCH] no longer crashes on invalid regex --- src/plugins/keywordNotify/index.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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); } },