summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/handlebars/base.js2
-rw-r--r--spec/qunit_spec.js4
2 files changed, 5 insertions, 1 deletions
diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js
index 9a75ada..b1cc4ba 100644
--- a/lib/handlebars/base.js
+++ b/lib/handlebars/base.js
@@ -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);
diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js
index 65100e0..56cb687 100644
--- a/spec/qunit_spec.js
+++ b/spec/qunit_spec.js
@@ -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() {