From 372ac26080d89f8dd249105f3cc381cf746ea7d0 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 18 Dec 2024 20:22:27 +0200 Subject: [PATCH] Do not allow empty or undefined variable names. Closes #3204 --- public/scripts/macros.js | 6 +++++- public/scripts/variables.js | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/public/scripts/macros.js b/public/scripts/macros.js index 0e4d7a8da..ea6b64b67 100644 --- a/public/scripts/macros.js +++ b/public/scripts/macros.js @@ -516,7 +516,11 @@ export function evaluateMacros(content, env, postProcessFn) { break; } - content = content.replace(macro.regex, (...args) => postProcessFn(macro.replace(...args))); + try { + content = content.replace(macro.regex, (...args) => postProcessFn(macro.replace(...args))); + } catch (e) { + console.warn(`Macro content can't be replaced: ${macro.regex} in ${content}`, e); + } } return content; diff --git a/public/scripts/variables.js b/public/scripts/variables.js index df22db8ad..5c77af187 100644 --- a/public/scripts/variables.js +++ b/public/scripts/variables.js @@ -46,6 +46,10 @@ function getLocalVariable(name, args = {}) { } function setLocalVariable(name, value, args = {}) { + if (!name) { + throw new Error('Variable name cannot be empty or undefined.'); + } + if (!chat_metadata.variables) { chat_metadata.variables = {}; }