From 6ae59dc8320629635c5444db87a3d83b35160556 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 25 Mar 2024 12:29:50 -0400 Subject: [PATCH 1/3] Prevent use of ...attributes in invalid places --- .../lib/parser/handlebars-node-visitors.ts | 7 +++ .../@glimmer/syntax/test/parser-node-test.ts | 48 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/packages/@glimmer/syntax/lib/parser/handlebars-node-visitors.ts b/packages/@glimmer/syntax/lib/parser/handlebars-node-visitors.ts index 6f7a620bb..cf20a8b09 100644 --- a/packages/@glimmer/syntax/lib/parser/handlebars-node-visitors.ts +++ b/packages/@glimmer/syntax/lib/parser/handlebars-node-visitors.ts @@ -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( + 'Cannot use ...attributes in a MustacheStatement', + this.source.spanFor(rawMustache.path.loc) + ); + } + if (isHBSLiteral(rawMustache.path)) { mustache = b.mustache({ path: this.acceptNode<(typeof rawMustache.path)['type']>(rawMustache.path), diff --git a/packages/@glimmer/syntax/test/parser-node-test.ts b/packages/@glimmer/syntax/test/parser-node-test.ts index dc8d3e150..07f7b6fcb 100644 --- a/packages/@glimmer/syntax/test/parser-node-test.ts +++ b/packages/@glimmer/syntax/test/parser-node-test.ts @@ -121,6 +121,54 @@ 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( + 'Cannot use ...attributes in a MustacheStatement', + '...attributes', + 'test-module', + 1, + 2 + ) + ); +}); + +test('attributes are not allowed as modifiers', (assert) => { + let t = '
'; + assert.throws( + () => { + parse(t, { meta: { moduleName: 'test-module' } }); + }, + syntaxErrorFor( + 'Cannot use ...attributes in a MustacheStatement', + '...attributes', + 'test-module', + 1, + 7 + ) + ); +}); + +test('attributes are not allowed as attribute values', (assert) => { + let t = '
'; + assert.throws( + () => { + parse(t, { meta: { moduleName: 'test-module' } }); + }, + syntaxErrorFor( + 'Cannot use ...attributes in a MustacheStatement', + '...attributes', + 'test-module', + 1, + 13 + ) + ); +}); + test('Handlebars embedded in an attribute (quoted)', () => { let t = 'some
content
done'; astEqual( From 6d4f7b92fa007f74ef9ef3d392c4033ca914e6d2 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 25 Mar 2024 12:48:20 -0400 Subject: [PATCH 2/3] Use more compact messaging --- .../lib/parser/handlebars-node-visitors.ts | 2 +- .../@glimmer/syntax/test/parser-node-test.ts | 24 +++---------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/packages/@glimmer/syntax/lib/parser/handlebars-node-visitors.ts b/packages/@glimmer/syntax/lib/parser/handlebars-node-visitors.ts index cf20a8b09..5a8aec4a3 100644 --- a/packages/@glimmer/syntax/lib/parser/handlebars-node-visitors.ts +++ b/packages/@glimmer/syntax/lib/parser/handlebars-node-visitors.ts @@ -222,7 +222,7 @@ export abstract class HandlebarsNodeVisitors extends Parser { if ('original' in rawMustache.path && rawMustache.path.original === '...attributes') { throw generateSyntaxError( - 'Cannot use ...attributes in a MustacheStatement', + 'Illegal use of ...attributes', this.source.spanFor(rawMustache.path.loc) ); } diff --git a/packages/@glimmer/syntax/test/parser-node-test.ts b/packages/@glimmer/syntax/test/parser-node-test.ts index 07f7b6fcb..0ca142b7f 100644 --- a/packages/@glimmer/syntax/test/parser-node-test.ts +++ b/packages/@glimmer/syntax/test/parser-node-test.ts @@ -127,13 +127,7 @@ test('attributes are not allowed as values', (assert) => { () => { parse(t, { meta: { moduleName: 'test-module' } }); }, - syntaxErrorFor( - 'Cannot use ...attributes in a MustacheStatement', - '...attributes', - 'test-module', - 1, - 2 - ) + syntaxErrorFor('Illegal use of ...attributes', '...attributes', 'test-module', 1, 2) ); }); @@ -143,13 +137,7 @@ test('attributes are not allowed as modifiers', (assert) => { () => { parse(t, { meta: { moduleName: 'test-module' } }); }, - syntaxErrorFor( - 'Cannot use ...attributes in a MustacheStatement', - '...attributes', - 'test-module', - 1, - 7 - ) + syntaxErrorFor('Illegal use of ...attributes', '...attributes', 'test-module', 1, 7) ); }); @@ -159,13 +147,7 @@ test('attributes are not allowed as attribute values', (assert) => { () => { parse(t, { meta: { moduleName: 'test-module' } }); }, - syntaxErrorFor( - 'Cannot use ...attributes in a MustacheStatement', - '...attributes', - 'test-module', - 1, - 13 - ) + syntaxErrorFor('Illegal use of ...attributes', '...attributes', 'test-module', 1, 13) ); }); From 97bdac0da90bfb8466e95cdcf6f07b6d98388a63 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Mon, 25 Mar 2024 12:50:58 -0400 Subject: [PATCH 3/3] Use Mustache loc instead of path --- .../@glimmer/syntax/lib/parser/handlebars-node-visitors.ts | 2 +- packages/@glimmer/syntax/test/parser-node-test.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/@glimmer/syntax/lib/parser/handlebars-node-visitors.ts b/packages/@glimmer/syntax/lib/parser/handlebars-node-visitors.ts index 5a8aec4a3..aad4535a2 100644 --- a/packages/@glimmer/syntax/lib/parser/handlebars-node-visitors.ts +++ b/packages/@glimmer/syntax/lib/parser/handlebars-node-visitors.ts @@ -223,7 +223,7 @@ export abstract class HandlebarsNodeVisitors extends Parser { if ('original' in rawMustache.path && rawMustache.path.original === '...attributes') { throw generateSyntaxError( 'Illegal use of ...attributes', - this.source.spanFor(rawMustache.path.loc) + this.source.spanFor(rawMustache.loc) ); } diff --git a/packages/@glimmer/syntax/test/parser-node-test.ts b/packages/@glimmer/syntax/test/parser-node-test.ts index 0ca142b7f..5bd0ba57b 100644 --- a/packages/@glimmer/syntax/test/parser-node-test.ts +++ b/packages/@glimmer/syntax/test/parser-node-test.ts @@ -127,7 +127,7 @@ test('attributes are not allowed as values', (assert) => { () => { parse(t, { meta: { moduleName: 'test-module' } }); }, - syntaxErrorFor('Illegal use of ...attributes', '...attributes', 'test-module', 1, 2) + syntaxErrorFor('Illegal use of ...attributes', '{{...attributes}}', 'test-module', 1, 0) ); }); @@ -137,7 +137,7 @@ test('attributes are not allowed as modifiers', (assert) => { () => { parse(t, { meta: { moduleName: 'test-module' } }); }, - syntaxErrorFor('Illegal use of ...attributes', '...attributes', 'test-module', 1, 7) + syntaxErrorFor('Illegal use of ...attributes', '{{...attributes}}', 'test-module', 1, 5) ); }); @@ -147,7 +147,7 @@ test('attributes are not allowed as attribute values', (assert) => { () => { parse(t, { meta: { moduleName: 'test-module' } }); }, - syntaxErrorFor('Illegal use of ...attributes', '...attributes', 'test-module', 1, 13) + syntaxErrorFor('Illegal use of ...attributes', '{{...attributes}}', 'test-module', 1, 11) ); });