Do not allow empty or undefined variable names.

Closes #3204
This commit is contained in:
Cohee
2024-12-18 20:22:27 +02:00
parent 00363cc206
commit 372ac26080
2 changed files with 9 additions and 1 deletions

View File

@ -516,7 +516,11 @@ export function evaluateMacros(content, env, postProcessFn) {
break; break;
} }
try {
content = content.replace(macro.regex, (...args) => postProcessFn(macro.replace(...args))); 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; return content;

View File

@ -46,6 +46,10 @@ function getLocalVariable(name, args = {}) {
} }
function setLocalVariable(name, value, args = {}) { function setLocalVariable(name, value, args = {}) {
if (!name) {
throw new Error('Variable name cannot be empty or undefined.');
}
if (!chat_metadata.variables) { if (!chat_metadata.variables) {
chat_metadata.variables = {}; chat_metadata.variables = {};
} }