Skip to content

Commit

Permalink
Prevent use of ...attributes in invalid places (#1582)
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli authored Mar 25, 2024
1 parent f3d2776 commit be49ccd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ export abstract class HandlebarsNodeVisitors extends Parser {
let mustache: ASTv1.MustacheStatement;
const { escaped, loc, strip } = rawMustache;

if ('original' in rawMustache.path && rawMustache.path.original === '...attributes') {
throw generateSyntaxError(
'Illegal use of ...attributes',
this.source.spanFor(rawMustache.loc)
);
}

if (isHBSLiteral(rawMustache.path)) {
mustache = b.mustache({
path: this.acceptNode<(typeof rawMustache.path)['type']>(rawMustache.path),
Expand Down
30 changes: 30 additions & 0 deletions packages/@glimmer/syntax/test/parser-node-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,36 @@ test('a piece of Handlebars with HTML', () => {
);
});

test('attributes are not allowed as values', (assert) => {
let t = '{{...attributes}}';
assert.throws(
() => {
parse(t, { meta: { moduleName: 'test-module' } });
},
syntaxErrorFor('Illegal use of ...attributes', '{{...attributes}}', 'test-module', 1, 0)
);
});

test('attributes are not allowed as modifiers', (assert) => {
let t = '<div {{...attributes}}></div>';
assert.throws(
() => {
parse(t, { meta: { moduleName: 'test-module' } });
},
syntaxErrorFor('Illegal use of ...attributes', '{{...attributes}}', 'test-module', 1, 5)
);
});

test('attributes are not allowed as attribute values', (assert) => {
let t = '<div class={{...attributes}}></div>';
assert.throws(
() => {
parse(t, { meta: { moduleName: 'test-module' } });
},
syntaxErrorFor('Illegal use of ...attributes', '{{...attributes}}', 'test-module', 1, 11)
);
});

test('Handlebars embedded in an attribute (quoted)', () => {
let t = 'some <div class="{{foo}}">content</div> done';
astEqual(
Expand Down

0 comments on commit be49ccd

Please sign in to comment.