From 1c3044486fbea163b40077a4dbdc7d187319aba9 Mon Sep 17 00:00:00 2001 From: Daniel Imfeld Date: Wed, 8 Apr 2020 02:13:05 +0000 Subject: [PATCH] Throw an error if an attribute name contains a bracket Fixes #4648 --- src/compiler/compile/nodes/Element.ts | 10 +++++++++- .../samples/attribute-invalid-name-2/errors.json | 15 +++++++++++++++ .../attribute-invalid-name-2/input.svelte | 1 + .../samples/attribute-invalid-name-3/errors.json | 16 ++++++++++++++++ .../attribute-invalid-name-3/input.svelte | 1 + .../samples/attribute-invalid-name-4/errors.json | 15 +++++++++++++++ .../attribute-invalid-name-4/input.svelte | 1 + .../samples/attribute-invalid-name-5/errors.json | 15 +++++++++++++++ .../attribute-invalid-name-5/input.svelte | 1 + .../samples/attribute-invalid-name/errors.json | 15 +++++++++++++++ .../samples/attribute-invalid-name/input.svelte | 1 + 11 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 test/validator/samples/attribute-invalid-name-2/errors.json create mode 100644 test/validator/samples/attribute-invalid-name-2/input.svelte create mode 100644 test/validator/samples/attribute-invalid-name-3/errors.json create mode 100644 test/validator/samples/attribute-invalid-name-3/input.svelte create mode 100644 test/validator/samples/attribute-invalid-name-4/errors.json create mode 100644 test/validator/samples/attribute-invalid-name-4/input.svelte create mode 100644 test/validator/samples/attribute-invalid-name-5/errors.json create mode 100644 test/validator/samples/attribute-invalid-name-5/input.svelte create mode 100644 test/validator/samples/attribute-invalid-name/errors.json create mode 100644 test/validator/samples/attribute-invalid-name/input.svelte diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 8c9c0bfe1841..a7dd9dd8e123 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -378,6 +378,14 @@ export default class Element extends Node { } } + + if (/[{}]/.test(name)) { + component.error(attribute, { + code: `illegal-attribute`, + message: `'${name}' is not a valid attribute name`, + }); + } + if (name === 'slot') { if (!attribute.is_static) { component.error(attribute, { @@ -768,4 +776,4 @@ function within_custom_element(parent: INode) { parent = parent.parent; } return false; -} \ No newline at end of file +} diff --git a/test/validator/samples/attribute-invalid-name-2/errors.json b/test/validator/samples/attribute-invalid-name-2/errors.json new file mode 100644 index 000000000000..8db9779a8649 --- /dev/null +++ b/test/validator/samples/attribute-invalid-name-2/errors.json @@ -0,0 +1,15 @@ +[{ + "code": "illegal-attribute", + "message": "'a}a' is not a valid attribute name", + "start": { + "line": 1, + "column": 3, + "character": 3 + }, + "end": { + "line": 1, + "column": 6, + "character": 6 + }, + "pos": 3 +}] diff --git a/test/validator/samples/attribute-invalid-name-2/input.svelte b/test/validator/samples/attribute-invalid-name-2/input.svelte new file mode 100644 index 000000000000..41dcea15ddcc --- /dev/null +++ b/test/validator/samples/attribute-invalid-name-2/input.svelte @@ -0,0 +1 @@ +

Test

diff --git a/test/validator/samples/attribute-invalid-name-3/errors.json b/test/validator/samples/attribute-invalid-name-3/errors.json new file mode 100644 index 000000000000..02cd395e09ab --- /dev/null +++ b/test/validator/samples/attribute-invalid-name-3/errors.json @@ -0,0 +1,16 @@ +[ +{ + "code": "illegal-attribute", + "message": "'a{a' is not a valid attribute name", + "start": { + "line": 1, + "column": 3, + "character": 3 + }, + "end": { + "line": 1, + "column": 6, + "character": 6 + }, + "pos": 3 +}] diff --git a/test/validator/samples/attribute-invalid-name-3/input.svelte b/test/validator/samples/attribute-invalid-name-3/input.svelte new file mode 100644 index 000000000000..cbf7b73c7857 --- /dev/null +++ b/test/validator/samples/attribute-invalid-name-3/input.svelte @@ -0,0 +1 @@ +

Test

diff --git a/test/validator/samples/attribute-invalid-name-4/errors.json b/test/validator/samples/attribute-invalid-name-4/errors.json new file mode 100644 index 000000000000..b7b5e8ef101d --- /dev/null +++ b/test/validator/samples/attribute-invalid-name-4/errors.json @@ -0,0 +1,15 @@ +[{ + "code": "illegal-attribute", + "message": "'}a' is not a valid attribute name", + "start": { + "line": 1, + "column": 3, + "character": 3 + }, + "end": { + "line": 1, + "column": 5, + "character": 5 + }, + "pos": 3 +}] diff --git a/test/validator/samples/attribute-invalid-name-4/input.svelte b/test/validator/samples/attribute-invalid-name-4/input.svelte new file mode 100644 index 000000000000..95381979b2d7 --- /dev/null +++ b/test/validator/samples/attribute-invalid-name-4/input.svelte @@ -0,0 +1 @@ +

Test

diff --git a/test/validator/samples/attribute-invalid-name-5/errors.json b/test/validator/samples/attribute-invalid-name-5/errors.json new file mode 100644 index 000000000000..586ec5c2e27d --- /dev/null +++ b/test/validator/samples/attribute-invalid-name-5/errors.json @@ -0,0 +1,15 @@ +[{ + "code": "illegal-attribute", + "message": "'a}' is not a valid attribute name", + "start": { + "line": 1, + "column": 3, + "character": 3 + }, + "end": { + "line": 1, + "column": 5, + "character": 5 + }, + "pos": 3 +}] diff --git a/test/validator/samples/attribute-invalid-name-5/input.svelte b/test/validator/samples/attribute-invalid-name-5/input.svelte new file mode 100644 index 000000000000..e36031f52aba --- /dev/null +++ b/test/validator/samples/attribute-invalid-name-5/input.svelte @@ -0,0 +1 @@ +

Test

diff --git a/test/validator/samples/attribute-invalid-name/errors.json b/test/validator/samples/attribute-invalid-name/errors.json new file mode 100644 index 000000000000..9bdde1ee46dc --- /dev/null +++ b/test/validator/samples/attribute-invalid-name/errors.json @@ -0,0 +1,15 @@ +[{ + "code": "illegal-attribute", + "message": "'}' is not a valid attribute name", + "start": { + "line": 1, + "column": 3, + "character": 3 + }, + "end": { + "line": 1, + "column": 4, + "character": 4 + }, + "pos": 3 +}] diff --git a/test/validator/samples/attribute-invalid-name/input.svelte b/test/validator/samples/attribute-invalid-name/input.svelte new file mode 100644 index 000000000000..56d9cfe23f0a --- /dev/null +++ b/test/validator/samples/attribute-invalid-name/input.svelte @@ -0,0 +1 @@ +

Test