Skip to content

Commit 827efb3

Browse files
authored
Merge pull request #1489 from cfwheels/architecture-3.0
Removing evaluate
2 parents c6f78a3 + 007319d commit 827efb3

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

vendor/wheels/model/validations.cfc

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)