2
0

🐛 (setVariable) Avoid octal number evalution

This commit is contained in:
Baptiste Arnaud
2024-01-25 11:28:27 +01:00
parent 5f0b36931a
commit ef05b71869
2 changed files with 7 additions and 0 deletions

View File

@@ -63,6 +63,8 @@ const evaluateSetVariableExpression =
const isSingleVariable = const isSingleVariable =
str.startsWith('{{') && str.endsWith('}}') && str.split('{{').length === 2 str.startsWith('{{') && str.endsWith('}}') && str.split('{{').length === 2
if (isSingleVariable) return parseVariables(variables)(str) if (isSingleVariable) return parseVariables(variables)(str)
// To avoid octal number evaluation
if (!isNaN(str as unknown as number) && /0[^.].+/.test(str)) return str
const evaluating = parseVariables(variables, { fieldToParse: 'id' })( const evaluating = parseVariables(variables, { fieldToParse: 'id' })(
str.includes('return ') ? str : `return ${str}` str.includes('return ') ? str : `return ${str}`
) )

View File

@@ -9,6 +9,11 @@ export const executeSetVariable = async ({
args, args,
}: ScriptToExecute): Promise<{ replyToSend: string | undefined }> => { }: ScriptToExecute): Promise<{ replyToSend: string | undefined }> => {
try { try {
// To avoid octal number evaluation
if (!isNaN(content as unknown as number) && /0[^.].+/.test(content))
return {
replyToSend: content,
}
const func = AsyncFunction( const func = AsyncFunction(
...args.map((arg) => arg.id), ...args.map((arg) => arg.id),
content.includes('return ') ? content : `return ${content}` content.includes('return ') ? content : `return ${content}`