Skip to content

Commit 56d1af4

Browse files
authored
a11y: warn about href="javascript:..." (#4733)
1 parent 8c4e726 commit 56d1af4

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/compiler/compile/nodes/Element.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export default class Element extends Node {
428428
if (attribute) {
429429
const value = attribute.get_static_value();
430430

431-
if (value === '' || value === '#') {
431+
if (value === '' || value === '#' || /^\W*javascript:/i.test(value)) {
432432
component.warn(attribute, {
433433
code: `a11y-invalid-attribute`,
434434
message: `A11y: '${value}' is not a valid ${attribute.name} attribute`
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<a>not actually a link</a>
22
<a href=''>invalid</a>
3-
<a href='#'>invalid</a>
3+
<a href='#'>invalid</a>
4+
<a href="javascript:void(0)">invalid</a>

test/validator/samples/a11y-anchor-is-valid/warnings.json

+15
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,20 @@
4343
"character": 61
4444
},
4545
"pos": 53
46+
},
47+
{
48+
"code": "a11y-invalid-attribute",
49+
"message": "A11y: 'javascript:void(0)' is not a valid href attribute",
50+
"start": {
51+
"line": 4,
52+
"column": 3,
53+
"character": 77
54+
},
55+
"end": {
56+
"line": 4,
57+
"column": 28,
58+
"character": 102
59+
},
60+
"pos": 77
4661
}
4762
]

0 commit comments

Comments
 (0)