Skip to content
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
2 changes: 1 addition & 1 deletion src/compiler/compile/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export default class Element extends Node {
if (attribute) {
const value = attribute.get_static_value();

if (value === '' || value === '#') {
if (value === '' || value === '#' || /^\W*javascript:/i.test(value)) {
component.warn(attribute, {
code: `a11y-invalid-attribute`,
message: `A11y: '${value}' is not a valid ${attribute.name} attribute`
Expand Down
3 changes: 2 additions & 1 deletion test/validator/samples/a11y-anchor-is-valid/input.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<a>not actually a link</a>
<a href=''>invalid</a>
<a href='#'>invalid</a>
<a href='#'>invalid</a>
<a href="javascript:void(0)">invalid</a>
15 changes: 15 additions & 0 deletions test/validator/samples/a11y-anchor-is-valid/warnings.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,20 @@
"character": 61
},
"pos": 53
},
{
"code": "a11y-invalid-attribute",
"message": "A11y: 'javascript:void(0)' is not a valid href attribute",
"start": {
"line": 4,
"column": 3,
"character": 77
},
"end": {
"line": 4,
"column": 28,
"character": 102
},
"pos": 77
}
]