@@ -412,10 +412,37 @@ component {
412412 local .rv = arguments .message ;
413413 // evaluate the error message if it contains pound signs
414414 if (Find (Chr (35 ), local .rv )) {
415- // use a try / catch here since it will fail if a pound sign is used that's not in an expression
416- try {
417- local .rv = Evaluate (De (local .rv ));
418- } catch (any e ) {
415+ // Extract variable names between # symbols
416+ local .regex = " (## ([^#chr (35 ) #]*)## |#### )" ;
417+ local .matches = REMatchNoCase (local .regex , local .rv );
418+ local .matchCount = ArrayLen (local .matches );
419+
420+ if (local .matchCount ) {
421+ for (local .i = 1 ; local .i <= local .matchCount ; local .i ++ ) {
422+ local .fullMatch = local .matches [local .i ]; // The full #variable# match
423+
424+ // Ensure it contains #
425+ if (Find (Chr (35 ), local .fullMatch )) {
426+ local .varName = ReplaceNoCase (local .fullMatch , " #chr (35 ) #" , " " , " ALL" );
427+
428+ // If empty ##, replace with a single #
429+ if (Len (local .varName ) EQ 0 ) {
430+ local .rv = ReplaceNoCase (local .rv , local .fullMatch , Chr (35 ), " one" );
431+ } else {
432+ // Retrieve variable value from function scope or arguments
433+ if (StructKeyExists (variables , local .varName )) {
434+ local .value = variables [local .varName ];
435+ } else if (StructKeyExists (arguments , local .varName )) {
436+ local .value = arguments [local .varName ];
437+ } else {
438+ local .value = local .fullMatch ; // Keep as-is if not found
439+ }
440+
441+ // Replace occurrences of #variable# with the actual value
442+ local .rv = ReplaceNoCase (local .rv , local .fullMatch , local .value , " one" );
443+ }
444+ }
445+ }
419446 }
420447 }
421448
0 commit comments