diff --git a/executor/index.ts b/executor/index.ts index 40c454ef52..3414481840 100644 --- a/executor/index.ts +++ b/executor/index.ts @@ -932,7 +932,8 @@ export class Executor { blockById, blockByName, context.blockStates, - block.metadata?.title || '' + block.metadata?.title || '', + block.metadata?.type || '' ) // Resolve environment variables diff --git a/executor/utils.ts b/executor/utils.ts index a528e276fb..de7a238dfa 100644 --- a/executor/utils.ts +++ b/executor/utils.ts @@ -1,3 +1,16 @@ +function stringifyValue(value: any): string { + if (typeof value === 'string') { + return `"${value.replace(/"/g, '\\"').replace(/\n/g, '\\n')}"` + } else if (value === null) { + return 'null' + } else if (typeof value === 'undefined') { + return 'undefined' + } else if (typeof value === 'object') { + return JSON.stringify(value) + } + return String(value) +} + export function resolveEnvVariables(value: any, environmentVariables: Record): any { if (typeof value === 'string') { const envMatches = value.match(/\{\{([^}]+)\}\}/g) @@ -29,7 +42,8 @@ export function resolveBlockReferences( blockById: Map, blockByName: Map, contextBlockStates: Map, - currentBlockTitle: string + currentBlockTitle: string, + currentBlockType: string ): string { const blockMatches = value.match(/<([^>]+)>/g) let resolvedValue = value @@ -65,12 +79,17 @@ export function resolveBlockReferences( replacementValue = replacementValue[part] } if (replacementValue !== undefined) { - resolvedValue = resolvedValue.replace( - match, - typeof replacementValue === 'object' - ? JSON.stringify(replacementValue) - : String(replacementValue) - ) + // For condition blocks, we need to properly stringify the value + if (currentBlockType === 'condition') { + resolvedValue = resolvedValue.replace(match, stringifyValue(replacementValue)) + } else { + resolvedValue = resolvedValue.replace( + match, + typeof replacementValue === 'object' + ? JSON.stringify(replacementValue) + : String(replacementValue) + ) + } } else { throw new Error( `No value found at path "${path}" in block "${sourceBlock.metadata?.title}".` @@ -78,5 +97,6 @@ export function resolveBlockReferences( } } } + return resolvedValue }