@@ -5,6 +5,7 @@ import { executeInE2B } from '@/lib/execution/e2b'
55import { executeInIsolatedVM } from '@/lib/execution/isolated-vm'
66import { CodeLanguage , DEFAULT_CODE_LANGUAGE , isValidCodeLanguage } from '@/lib/execution/languages'
77import { createLogger } from '@/lib/logs/console/logger'
8+ import { escapeRegExp , normalizeName , REFERENCE } from '@/executor/constants'
89import {
910 createEnvVarPattern ,
1011 createWorkflowVariablePattern ,
@@ -405,7 +406,7 @@ function resolveWorkflowVariables(
405406
406407 // Find the variable by name (workflowVariables is indexed by ID, values are variable objects)
407408 const foundVariable = Object . entries ( workflowVariables ) . find (
408- ( [ _ , variable ] ) => ( variable . name || '' ) . replace ( / \s + / g , '' ) === variableName
409+ ( [ _ , variable ] ) => normalizeName ( variable . name || '' ) === variableName
409410 )
410411
411412 let variableValue : unknown = ''
@@ -513,31 +514,26 @@ function resolveTagVariables(
513514) : string {
514515 let resolvedCode = code
515516
516- const tagMatches = resolvedCode . match ( / < ( [ a - z A - Z _ ] [ a - z A - Z 0 - 9 _ . ] * [ a - z A - Z 0 - 9 _ ] ) > / g) || [ ]
517+ const tagPattern = new RegExp (
518+ `${ REFERENCE . START } ([a-zA-Z_][a-zA-Z0-9_${ REFERENCE . PATH_DELIMITER } ]*[a-zA-Z0-9_])${ REFERENCE . END } ` ,
519+ 'g'
520+ )
521+ const tagMatches = resolvedCode . match ( tagPattern ) || [ ]
517522
518523 for ( const match of tagMatches ) {
519- const tagName = match . slice ( 1 , - 1 ) . trim ( )
524+ const tagName = match . slice ( REFERENCE . START . length , - REFERENCE . END . length ) . trim ( )
520525
521526 // Handle nested paths like "getrecord.response.data" or "function1.response.result"
522527 // First try params, then blockData directly, then try with block name mapping
523528 let tagValue = getNestedValue ( params , tagName ) || getNestedValue ( blockData , tagName ) || ''
524529
525530 // If not found and the path starts with a block name, try mapping the block name to ID
526- if ( ! tagValue && tagName . includes ( '.' ) ) {
527- const pathParts = tagName . split ( '.' )
531+ if ( ! tagValue && tagName . includes ( REFERENCE . PATH_DELIMITER ) ) {
532+ const pathParts = tagName . split ( REFERENCE . PATH_DELIMITER )
528533 const normalizedBlockName = pathParts [ 0 ] // This should already be normalized like "function1"
529534
530- // Find the block ID by looking for a block name that normalizes to this value
531- let blockId = null
532-
533- for ( const [ blockName , id ] of Object . entries ( blockNameMapping ) ) {
534- // Apply the same normalization logic as the UI: remove spaces and lowercase
535- const normalizedName = blockName . replace ( / \s + / g, '' ) . toLowerCase ( )
536- if ( normalizedName === normalizedBlockName ) {
537- blockId = id
538- break
539- }
540- }
535+ // Direct lookup using normalized block name
536+ const blockId = blockNameMapping [ normalizedBlockName ] ?? null
541537
542538 if ( blockId ) {
543539 const remainingPath = pathParts . slice ( 1 ) . join ( '.' )
@@ -617,13 +613,6 @@ function getNestedValue(obj: any, path: string): any {
617613 } , obj )
618614}
619615
620- /**
621- * Escape special regex characters in a string
622- */
623- function escapeRegExp ( string : string ) : string {
624- return string . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' )
625- }
626-
627616/**
628617 * Remove one trailing newline from stdout
629618 * This handles the common case where print() or console.log() adds a trailing \n
0 commit comments