Skip to content

Commit 6c6a2bf

Browse files
committed
FIO-9942: protected eval extends @formio/js default eval to fix interpolation issues
1 parent 0c4716d commit 6c6a2bf

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/ProtectedEvaluator.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Interpreter from '@formio/js-interpreter';
33

44
const baseEvaluator = (FormioUtils.Evaluator as any).evaluator;
55
const baseEvaluate = (FormioUtils.Evaluator as any).evaluate;
6+
const DefaultEvaluator = (FormioUtils as any).DefaultEvaluator;
67

78
export interface IEvaluator {
89
noeval?: boolean;
@@ -13,19 +14,21 @@ export interface IEvaluator {
1314

1415
const excludedVariables = ['instance', 'self', 'options'];
1516

16-
const Evaluator: IEvaluator = {
17-
noeval: true,
18-
protectedEval: true,
19-
evaluator: (func: string | any, ...params: any[]): () => any => {
20-
if (!Evaluator.protectedEval) {
17+
export class Evaluator extends DefaultEvaluator {
18+
noeval = true;
19+
protectedEval = true;
20+
21+
evaluator(func: string | any, ...params: any[]): () => any {
22+
if (!this.protectedEval) {
2123
return baseEvaluator(func, ...params);
2224
}
2325

2426
console.warn('No evaluations allowed for safe eval.');
2527
return () => undefined;
26-
},
27-
evaluate: (func: string | any, args: any, ...rest: any[]): any => {
28-
if (!Evaluator.protectedEval || typeof func !== 'string') {
28+
};
29+
30+
evaluate(func: string | any, args: any, ...rest: any[]): any {
31+
if (!this.protectedEval || typeof func !== 'string') {
2932
return baseEvaluate(func, args, ...rest);
3033
}
3134

@@ -48,7 +51,7 @@ const Evaluator: IEvaluator = {
4851
interpreter.run();
4952
const result = interpreter.getProperty(interpreter.globalObject, 'result');
5053
return interpreter.pseudoToNative(result);
51-
},
54+
};
5255
};
5356

54-
export default Evaluator;
57+
export default new Evaluator();

0 commit comments

Comments
 (0)