Spacebars: Disallow non-initial this in paths

Apparently `../this` used to work as a synonym for `..` in Handlebars, but in Spacebars it actually would look for a property named `this`, which caused confusing breaking changes in apps.
This commit is contained in:
David Greenspan
2014-03-04 15:40:23 -08:00
parent f302d25dc1
commit 8d77b770fb
2 changed files with 13 additions and 3 deletions

View File

@@ -121,6 +121,12 @@ Tinytest.add("spacebars - stache tags", function (test) {
['NUMBER', 2, 'y']]});
run('{{> foo x=1 y=2 z}}',
"Can't have a non-keyword argument");
run('{{true.foo}}', "Can't use");
run('{{foo.this}}', "Can only use");
run('{{./this}}', "Can only use");
run('{{../this}}', "Can only use");
});

View File

@@ -141,9 +141,13 @@ TemplateTag.parse = function (scannerOrString) {
segments.push(seg);
} else {
var id = scanIdentifier(! segments.length);
if (id === 'this' && ! segments.length) {
// initial `this`
segments.push('.');
if (id === 'this') {
if (! segments.length) {
// initial `this`
segments.push('.');
} else {
error("Can only use `this` at the beginning of a path.\nInstead of `foo.this` or `../this`, just write `foo` or `..`.");
}
} else {
segments.push(id);
}