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

Throw an error if an attribute name contains an invalid character #4650

Merged
merged 3 commits into from
Apr 23, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/compiler/compile/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@ export default class Element extends Node {
}
}


if (/(^[0-9-.])|[\^$@%&#?!|()[\]{}^*+~;]/.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, {
Expand Down Expand Up @@ -768,4 +776,4 @@ function within_custom_element(parent: INode) {
parent = parent.parent;
}
return false;
}
}
15 changes: 15 additions & 0 deletions test/validator/samples/attribute-invalid-name-2/errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[{
"code": "illegal-attribute",
"message": "'3aa' is not a valid attribute name",
"start": {
"line": 1,
"column": 3,
"character": 3
},
"end": {
"line": 1,
"column": 12,
"character": 12
},
"pos": 3
}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p 3aa="abc">Test</p>
15 changes: 15 additions & 0 deletions test/validator/samples/attribute-invalid-name-3/errors.json
Original file line number Diff line number Diff line change
@@ -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
}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p a*a>Test</p>
15 changes: 15 additions & 0 deletions test/validator/samples/attribute-invalid-name-4/errors.json
Original file line number Diff line number Diff line change
@@ -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
}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p -a>Test</p>
15 changes: 15 additions & 0 deletions test/validator/samples/attribute-invalid-name-5/errors.json
Original file line number Diff line number Diff line change
@@ -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": 11,
"character": 11
},
"pos": 3
}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p a;="abc">Test</p>
15 changes: 15 additions & 0 deletions test/validator/samples/attribute-invalid-name/errors.json
Original file line number Diff line number Diff line change
@@ -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
}]
1 change: 1 addition & 0 deletions test/validator/samples/attribute-invalid-name/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p }>Test</p>