Skip to content

Commit 9d5aa36

Browse files
committedJan 13, 2020
fix: don't wrap helpers that are not functions
- helpers should always be a function, but in #1639 one seems to be undefined. This was not a problem before 4.6 because helpers weren't wrapped then. Now, we must take care only to wrap helpers (when adding the "lookupProperty" function to the options), if they are really functions.
1 parent 14ba3d0 commit 9d5aa36

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
 

‎lib/handlebars/internal/wrapHelper.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
export function wrapHelper(helper, transformOptionsFn) {
2+
if (typeof helper !== 'function') {
3+
// This should not happen, but apparently it does in https://github.com/wycats/handlebars.js/issues/1639
4+
// We try to make the wrapper least-invasive by not wrapping it, if the helper is not a function.
5+
return helper;
6+
}
27
let wrapper = function(/* dynamic arguments */) {
38
const options = arguments[arguments.length - 1];
49
arguments[arguments.length - 1] = transformOptionsFn(options);

‎spec/regressions.js

+9
Original file line numberDiff line numberDiff line change
@@ -518,4 +518,13 @@ describe('Regressions', function() {
518518
sinon.restore();
519519
});
520520
});
521+
522+
describe("GH-1639: TypeError: Cannot read property 'apply' of undefined\" when handlebars version > 4.6.0 (undocumented, deprecated usage)", function() {
523+
it('should treat undefined helpers like non-existing helpers', function() {
524+
expectTemplate('{{foo}}')
525+
.withHelper('foo', undefined)
526+
.withInput({ foo: 'bar' })
527+
.toCompileTo('bar');
528+
});
529+
});
521530
});

0 commit comments

Comments
 (0)
Please sign in to comment.