Skip to content

Commit

Permalink
a11y: warn about href="javascript:..." (#4733)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjj6198 authored Apr 28, 2020
1 parent 8c4e726 commit 56d1af4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
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
}
]

0 comments on commit 56d1af4

Please sign in to comment.