From d50db1d3fb2a5f62ac694e3ea5c2076308af421f Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Mon, 30 Jun 2025 12:45:36 -0700 Subject: [PATCH] add dot check --- apps/sim/app/api/function/execute/route.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/sim/app/api/function/execute/route.ts b/apps/sim/app/api/function/execute/route.ts index 066ef37cbe..9022368c5a 100644 --- a/apps/sim/app/api/function/execute/route.ts +++ b/apps/sim/app/api/function/execute/route.ts @@ -39,11 +39,13 @@ function resolveCodeVariables( resolvedCode = resolvedCode.replace(new RegExp(escapeRegExp(match), 'g'), safeVarName) } - // Resolve tags with syntax - const tagMatches = resolvedCode.match(/<([a-zA-Z_][a-zA-Z0-9_]*)>/g) || [] + // Resolve tags with syntax (including nested paths like ) + const tagMatches = resolvedCode.match(/<([a-zA-Z_][a-zA-Z0-9_.]*[a-zA-Z0-9_])>/g) || [] for (const match of tagMatches) { const tagName = match.slice(1, -1).trim() - const tagValue = params[tagName] || '' + + // Handle nested paths like "getrecord.response.data" + const tagValue = getNestedValue(params, tagName) || '' // Instead of injecting large JSON directly, create a variable reference const safeVarName = `__tag_${tagName.replace(/[^a-zA-Z0-9_]/g, '_')}` @@ -56,6 +58,17 @@ function resolveCodeVariables( return { resolvedCode, contextVariables } } +/** + * Get nested value from object using dot notation path + */ +function getNestedValue(obj: any, path: string): any { + if (!obj || !path) return undefined + + return path.split('.').reduce((current, key) => { + return current && typeof current === 'object' ? current[key] : undefined + }, obj) +} + /** * Escape special regex characters in a string */