Merge pull request #66 from rgrove/fix-empty-array-if

The "if" block helper shouldn't treat empty arrays as truthy
This commit is contained in:
Alan Johnson
2011-06-27 03:15:50 -07:00
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ Handlebars.registerHelper('each', function(context, fn, inverse) {
});
Handlebars.registerHelper('if', function(context, fn, inverse) {
if(!context || context == []) {
if(!context || Handlebars.Utils.isEmpty(context)) {
return inverse(this);
} else {
return fn(this);
+4
View File
@@ -518,6 +518,10 @@ test("if", function() {
"if with boolean argument does not show the contents when false");
shouldCompileTo(string, {world: "world"}, "cruel world!",
"if with undefined does not show the contents");
shouldCompileTo(string, {goodbye: ['foo'], world: "world"}, "GOODBYE cruel world!",
"if with non-empty array shows the contents");
shouldCompileTo(string, {goodbye: [], world: "world"}, "cruel world!",
"if with empty array does not show the contents");
});
test("each", function() {