Skip to content

Commit 8353f91

Browse files
committed
Removing evaluate
Removed the use of the evaluate function and instead replaced it with the code that searches for the variables enclosed within ## and then replaces it with the variable's value which it searches from the variables and arguments scopes. If there is no variable between two # then it simply returns a single #
1 parent c6f78a3 commit 8353f91

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

vendor/wheels/model/validations.cfc

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,31 @@ 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+
local.value = StructFind(variables, local.varName, StructFind(arguments, local.varName, local.fullMatch));
434+
435+
// Replace occurrences of #variable# with the actual value
436+
local.rv = ReplaceNoCase(local.rv, local.fullMatch, local.value, "one");
437+
}
438+
}
439+
}
419440
}
420441
}
421442

0 commit comments

Comments
 (0)