mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #3205 from SillyTavern/forbid-empty-varnames
Do not allow empty or undefined variable names.
This commit is contained in:
@@ -516,7 +516,11 @@ export function evaluateMacros(content, env, postProcessFn) {
|
|||||||
break;
|
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;
|
return content;
|
||||||
|
@@ -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 = {};
|
||||||
}
|
}
|
||||||
@@ -99,6 +103,10 @@ function getGlobalVariable(name, args = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setGlobalVariable(name, value, args = {}) {
|
function setGlobalVariable(name, value, args = {}) {
|
||||||
|
if (!name) {
|
||||||
|
throw new Error('Variable name cannot be empty or undefined.');
|
||||||
|
}
|
||||||
|
|
||||||
if (args.index !== undefined) {
|
if (args.index !== undefined) {
|
||||||
try {
|
try {
|
||||||
let globalVariable = JSON.parse(extension_settings.variables.global[name] ?? 'null');
|
let globalVariable = JSON.parse(extension_settings.variables.global[name] ?? 'null');
|
||||||
|
Reference in New Issue
Block a user