Skip to content

Commit

Permalink
fix: don't wrap helpers that are not functions
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
nknapp committed Jan 13, 2020
1 parent 14ba3d0 commit 9d5aa36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/handlebars/internal/wrapHelper.js
@@ -1,4 +1,9 @@
export function wrapHelper(helper, transformOptionsFn) {
if (typeof helper !== 'function') {
// This should not happen, but apparently it does in https://github.com/wycats/handlebars.js/issues/1639
// We try to make the wrapper least-invasive by not wrapping it, if the helper is not a function.
return helper;
}
let wrapper = function(/* dynamic arguments */) {
const options = arguments[arguments.length - 1];
arguments[arguments.length - 1] = transformOptionsFn(options);
Expand Down
9 changes: 9 additions & 0 deletions spec/regressions.js
Expand Up @@ -518,4 +518,13 @@ describe('Regressions', function() {
sinon.restore();
});
});

describe("GH-1639: TypeError: Cannot read property 'apply' of undefined\" when handlebars version > 4.6.0 (undocumented, deprecated usage)", function() {
it('should treat undefined helpers like non-existing helpers', function() {
expectTemplate('{{foo}}')
.withHelper('foo', undefined)
.withInput({ foo: 'bar' })
.toCompileTo('bar');
});
});
});

0 comments on commit 9d5aa36

Please sign in to comment.