Fixed issue where using {{.}} as an expression could cause the fallback hash to be rendered instead, if {{.}} is empty.

This commit is contained in:
Alan Johnson
2010-10-12 21:54:10 -04:00
parent 7041b3a869
commit 295cfe5fd1
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -359,7 +359,7 @@ Handlebars.Compiler.prototype = {
} else if (parts.length == 1) {
return "(!Handlebars.isEmpty(context['" + parts[0] + "']) ? context['" + parts[0] + "'] : fallback['" + parts[0] + "'])";
} else {
return "(!Handlebars.isEmpty(context) ? context : fallback)";
return "(!Handlebars.isEmpty(context) ? context : null)";
}
},
+4
View File
@@ -110,6 +110,10 @@ test("bad idea nested paths", function() {
shouldCompileTo(string, hash, "world world world ", "Same context (.) is ignored in paths");
});
test("that current context path ({{.}}) doesn't hit fallback", function() {
shouldCompileTo("test: {{.}}", [null, {helper: "awesome"}], "test: ");
});
test("complex but empty paths", function() {
shouldCompileTo("{{person/name}}", {person: {name: null}}, "");
shouldCompileTo("{{person/name}}", {person: {}}, "");