Merge pull request #3205 from SillyTavern/forbid-empty-varnames Do not allow empty or undefined variable names.
Signed| @@ -516,7 +516,11 @@ export function evaluateMacros(content, env, postProcessFn) { | |||
| 516 | break; | 516 | break; |
| 517 | } | 517 | } |
| 518 | 518 | ||
| 519 | content = content.replace(macro.regex, (...args) => postProcessFn(macro.replace(...args))); | 519 | try { |
| 520 | content = content.replace(macro.regex, (...args) => postProcessFn(macro.replace(...args))); | ||
| 521 | } catch (e) { | ||
| 522 | console.warn(`Macro content can't be replaced: ${macro.regex} in ${content}`, e); | ||
| 523 | } | ||
| 520 | } | 524 | } |
| 521 | 525 | ||
| 522 | return content; | 526 | return content; |
| @@ -46,6 +46,10 @@ function getLocalVariable(name, args = {}) { | |||
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | function setLocalVariable(name, value, args = {}) { | 48 | function setLocalVariable(name, value, args = {}) { |
| 49 | if (!name) { | ||
| 50 | throw new Error('Variable name cannot be empty or undefined.'); | ||
| 51 | } | ||
| 52 | |||
| 49 | if (!chat_metadata.variables) { | 53 | if (!chat_metadata.variables) { |
| 50 | chat_metadata.variables = {}; | 54 | chat_metadata.variables = {}; |
| 51 | } | 55 | } |
| @@ -99,6 +103,10 @@ function getGlobalVariable(name, args = {}) { | |||
| 99 | } | 103 | } |
| 100 | 104 | ||
| 101 | function setGlobalVariable(name, value, args = {}) { | 105 | function setGlobalVariable(name, value, args = {}) { |
| 106 | if (!name) { | ||
| 107 | throw new Error('Variable name cannot be empty or undefined.'); | ||
| 108 | } | ||
| 109 | |||
| 102 | if (args.index !== undefined) { | 110 | if (args.index !== undefined) { |
| 103 | try { | 111 | try { |
| 104 | let globalVariable = JSON.parse(extension_settings.variables.global[name] ?? 'null'); | 112 | let globalVariable = JSON.parse(extension_settings.variables.global[name] ?? 'null'); |