Skip to content

Commit fe8709b

Browse files
committed
Fix handlebars-lang#1748 where allowed prototype methods are not called
1 parent b4a54ad commit fe8709b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/handlebars/runtime.js

+3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ export function template(templateSpec, env) {
133133
}
134134

135135
if (resultIsAllowed(result, container.protoAccessControl, propertyName)) {
136+
if (typeof result === 'function') {
137+
return parent[propertyName]();
138+
}
136139
return result;
137140
}
138141
return undefined;

spec/security.js

+11
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,17 @@ describe('security issues', function () {
285285
})
286286
.toCompileTo('abc');
287287
});
288+
289+
it('should use a proto method to trim a string', function () {
290+
expectTemplate('{{aString.trim}}')
291+
.withInput({ aString: ' abc ' })
292+
.withRuntimeOptions({
293+
allowedProtoMethods: {
294+
trim: true,
295+
},
296+
})
297+
.toCompileTo('abc');
298+
});
288299
});
289300

290301
describe('control access to prototype non-methods via "allowedProtoProperties" and "allowProtoPropertiesByDefault', function () {

0 commit comments

Comments
 (0)