Skip to content

Commit be49ccd

Browse files
Prevent use of ...attributes in invalid places (#1582)
1 parent f3d2776 commit be49ccd

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

packages/@glimmer/syntax/lib/parser/handlebars-node-visitors.ts

+7
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ export abstract class HandlebarsNodeVisitors extends Parser {
220220
let mustache: ASTv1.MustacheStatement;
221221
const { escaped, loc, strip } = rawMustache;
222222

223+
if ('original' in rawMustache.path && rawMustache.path.original === '...attributes') {
224+
throw generateSyntaxError(
225+
'Illegal use of ...attributes',
226+
this.source.spanFor(rawMustache.loc)
227+
);
228+
}
229+
223230
if (isHBSLiteral(rawMustache.path)) {
224231
mustache = b.mustache({
225232
path: this.acceptNode<(typeof rawMustache.path)['type']>(rawMustache.path),

packages/@glimmer/syntax/test/parser-node-test.ts

+30
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,36 @@ test('a piece of Handlebars with HTML', () => {
121121
);
122122
});
123123

124+
test('attributes are not allowed as values', (assert) => {
125+
let t = '{{...attributes}}';
126+
assert.throws(
127+
() => {
128+
parse(t, { meta: { moduleName: 'test-module' } });
129+
},
130+
syntaxErrorFor('Illegal use of ...attributes', '{{...attributes}}', 'test-module', 1, 0)
131+
);
132+
});
133+
134+
test('attributes are not allowed as modifiers', (assert) => {
135+
let t = '<div {{...attributes}}></div>';
136+
assert.throws(
137+
() => {
138+
parse(t, { meta: { moduleName: 'test-module' } });
139+
},
140+
syntaxErrorFor('Illegal use of ...attributes', '{{...attributes}}', 'test-module', 1, 5)
141+
);
142+
});
143+
144+
test('attributes are not allowed as attribute values', (assert) => {
145+
let t = '<div class={{...attributes}}></div>';
146+
assert.throws(
147+
() => {
148+
parse(t, { meta: { moduleName: 'test-module' } });
149+
},
150+
syntaxErrorFor('Illegal use of ...attributes', '{{...attributes}}', 'test-module', 1, 11)
151+
);
152+
});
153+
124154
test('Handlebars embedded in an attribute (quoted)', () => {
125155
let t = 'some <div class="{{foo}}">content</div> done';
126156
astEqual(

0 commit comments

Comments
 (0)