Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent use of ...attributes in invalid places #1582

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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