mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
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:
@@ -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");
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user