Skip to content

Commit f00adfe

Browse files
committed
Try to prevent function access
1 parent bbfcd94 commit f00adfe

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

defaultMethods.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -862,18 +862,22 @@ defaultMethods.var.compile = function (data, buildState) {
862862
const pieces = splitPath(key)
863863
const [top] = pieces
864864
buildState.varTop.add(top)
865+
866+
if (!buildState.engine.allowFunctions) buildState.methods.preventFunctions = a => typeof a === 'function' ? null : a
867+
else buildState.methods.preventFunctions = a => a
868+
865869
// support older versions of node
866870
if (!chainingSupported) {
867-
return `(((a,b) => (typeof a === 'undefined' || a === null) ? b : a)(${pieces.reduce(
871+
return `(methods.preventFunctions(((a,b) => (typeof a === 'undefined' || a === null) ? b : a)(${pieces.reduce(
868872
(text, i) => {
869873
return `(${text}||0)[${JSON.stringify(i)}]`
870874
},
871875
'(context||0)'
872-
)}, ${buildString(defaultValue, buildState)}))`
876+
)}, ${buildString(defaultValue, buildState)})))`
873877
}
874-
return `(context${pieces
878+
return `(methods.preventFunctions(context${pieces
875879
.map((i) => `?.[${JSON.stringify(i)}]`)
876-
.join('')} ?? ${buildString(defaultValue, buildState)})`
880+
.join('')} ?? ${buildString(defaultValue, buildState)}))`
877881
}
878882
buildState.useContext = true
879883
return false

0 commit comments

Comments
 (0)