Updated the path parsing in lookupFor to be a bit smarter and added parse errors for some of the more tricky ones.
This commit is contained in:
+1
-1
@@ -106,7 +106,7 @@ Handlebars.Compiler.prototype = {
|
||||
}
|
||||
break;
|
||||
case ".":
|
||||
throw new HandleBars.ParseError("'.' is not supported in path expressions.")
|
||||
// do nothing - using .'s is pretty dumb, but it's also basically free for us to support
|
||||
break;
|
||||
default:
|
||||
readDepth = true;
|
||||
|
||||
+8
-3
@@ -31,8 +31,7 @@ test("nested paths", function() {
|
||||
"Goodbye beautiful world!", "Nested paths access nested objects");
|
||||
});
|
||||
|
||||
test("dumb nested paths", function() {
|
||||
var string = "{{#goodbyes}}{{../name/../name}}{{/goodbyes}}";
|
||||
test("bad idea nested paths", function() {
|
||||
var caught = false;
|
||||
try {
|
||||
Handlebars.compile("{{#goodbyes}}{{../name/../name}}{{/goodbyes}}");
|
||||
@@ -41,9 +40,14 @@ test("dumb nested paths", function() {
|
||||
caught = true;
|
||||
}
|
||||
}
|
||||
equals(caught, true, "Jumping out of context (..) doesn't work after moving into context.");
|
||||
equals(caught, true, "Cannot jump (..) into previous context after moving into context.");
|
||||
|
||||
var string = "{{#goodbyes}}{{.././world}} {{/goodbyes}}";
|
||||
var hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"};
|
||||
shouldCompileTo(string, hash, "world world world ", "Same context (.) is ignored in paths");
|
||||
});
|
||||
|
||||
|
||||
module("blocks");
|
||||
|
||||
test("array", function() {
|
||||
@@ -54,6 +58,7 @@ test("array", function() {
|
||||
|
||||
shouldCompileTo(string, {goodbyes: [], world: "world"}, "cruel world!",
|
||||
"Arrays ignore the contents when empty");
|
||||
|
||||
});
|
||||
|
||||
test("nested iteration", function() {
|
||||
|
||||
Reference in New Issue
Block a user