Fixed issue where using {{.}} as an expression could cause the fallback hash to be rendered instead, if {{.}} is empty.
This commit is contained in:
+1
-1
@@ -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)";
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -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: {}}, "");
|
||||
|
||||
Reference in New Issue
Block a user