Skip to content

Commit b5f03c9

Browse files
committed
Merge pull request #870 from max-b/master
Registering undefined partial throws exception.
2 parents d595ebc + b87e601 commit b5f03c9

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/handlebars/base.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ HandlebarsEnvironment.prototype = {
4747
if (toString.call(name) === objectType) {
4848
Utils.extend(this.partials, name);
4949
} else {
50+
if (typeof partial === 'undefined') {
51+
throw new Exception('Attempting to register a partial as undefined');
52+
}
5053
this.partials[name] = partial;
5154
}
5255
},

spec/partials.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ describe('partials', function() {
4141

4242
it("rendering undefined partial throws an exception", function() {
4343
shouldThrow(function() {
44-
var template = CompilerContext.compile("{{> whatever}}");
45-
template();
44+
var template = CompilerContext.compile("{{> whatever}}");
45+
template();
4646
}, Handlebars.Exception, 'The partial whatever could not be found');
4747
});
4848

49+
it("registering undefined partial throws an exception", function() {
50+
shouldThrow(function() {
51+
var undef;
52+
handlebarsEnv.registerPartial('undefined_test', undef);
53+
}, Handlebars.Exception, 'Attempting to register a partial as undefined');
54+
});
55+
4956
it("rendering template partial in vm mode throws an exception", function() {
5057
shouldThrow(function() {
5158
var template = CompilerContext.compile("{{> whatever}}");
@@ -64,10 +71,10 @@ describe('partials', function() {
6471
});
6572

6673
it("GH-14: a partial preceding a selector", function() {
67-
var string = "Dudes: {{>dude}} {{another_dude}}";
68-
var dude = "{{name}}";
69-
var hash = {name:"Jeepers", another_dude:"Creepers"};
70-
shouldCompileToWithPartials(string, [hash, {}, {dude:dude}], true, "Dudes: Jeepers Creepers", "Regular selectors can follow a partial");
74+
var string = "Dudes: {{>dude}} {{another_dude}}";
75+
var dude = "{{name}}";
76+
var hash = {name:"Jeepers", another_dude:"Creepers"};
77+
shouldCompileToWithPartials(string, [hash, {}, {dude:dude}], true, "Dudes: Jeepers Creepers", "Regular selectors can follow a partial");
7178
});
7279

7380
it("Partials with slash paths", function() {

0 commit comments

Comments
 (0)