Skip to content

Commit c9d4215

Browse files
committed
Implement better tests for allowFunctions
1 parent f00adfe commit c9d4215

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

general.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,25 @@ describe('Various Test Cases', () => {
126126
for (const engine of [...normalEngines, ...permissiveEngines]) await testEngine(engine, { get: [{ var: 'selected' }, { var: 'key' }] }, { selected: { 'b.c': 2 }, key: 'b\\.c' }, 2)
127127
})
128128

129+
it('is able to avoid returning functions', async () => {
130+
for (const engine of [...normalEngines, ...permissiveEngines]) await testEngine(engine, { var: 'toString' }, 'hello', null)
131+
})
132+
133+
it('is able to return functions if enabled', async () => {
134+
try {
135+
for (const engine of [...normalEngines, ...permissiveEngines]) {
136+
engine.allowFunctions = true
137+
engine.addMethod('typeof', (value) => typeof value)
138+
await testEngine(engine, { typeof: { var: 'toString' } }, 'hello', 'function')
139+
}
140+
} finally {
141+
for (const engine of [...normalEngines, ...permissiveEngines]) {
142+
engine.allowFunctions = false
143+
delete engine.methods.typeof
144+
}
145+
}
146+
})
147+
129148
it('is able to handle path escaping in a var call', async () => {
130149
for (const engine of [...normalEngines, ...permissiveEngines]) await testEngine(engine, { var: 'hello\\.world' }, { 'hello.world': 2 }, 2)
131150
})

0 commit comments

Comments
 (0)