File tree Expand file tree Collapse file tree 3 files changed +42
-6
lines changed
test/validator/samples/a11y-anchor-in-svg-is-valid Expand file tree Collapse file tree 3 files changed +42
-6
lines changed Original file line number Diff line number Diff line change @@ -106,14 +106,21 @@ export default function a11y(
106
106
}
107
107
}
108
108
109
+ function shouldHaveValidHref ( attribute ) {
110
+ const href = attributeMap . get ( attribute ) ;
111
+ const value = getStaticAttributeValue ( node , attribute ) ;
112
+ if ( value === '' || value === '#' ) {
113
+ validator . warn ( `A11y: '${ value } ' is not a valid ${ attribute } attribute` , href . start ) ;
114
+ }
115
+ }
116
+
109
117
if ( node . name === 'a' ) {
110
- // anchor-is-valid
111
- const href = attributeMap . get ( 'href' ) ;
112
118
if ( attributeMap . has ( 'href' ) ) {
113
- const value = getStaticAttributeValue ( node , 'href' ) ;
114
- if ( value === '' || value === '#' ) {
115
- validator . warn ( `A11y: '${ value } ' is not a valid href attribute` , href . start ) ;
116
- }
119
+ // anchor-is-valid
120
+ shouldHaveValidHref ( 'href' )
121
+ } else if ( attributeMap . has ( 'xlink:href' ) ) {
122
+ // anchor-in-svg-is-valid
123
+ shouldHaveValidHref ( 'xlink:href' )
117
124
} else {
118
125
validator . warn ( `A11y: <a> element should have an href attribute` , node . start ) ;
119
126
}
Original file line number Diff line number Diff line change
1
+ < svg > < text > < a > not actually a link</ a > </ text > </ svg >
2
+ < svg > < text > < a xlink:href =''> not actually a link</ a > </ text > </ svg >
3
+ < svg > < text > < a xlink:href ='# '> not actually a link</ a > </ text > </ svg >
Original file line number Diff line number Diff line change
1
+ [
2
+ {
3
+ "message" : " A11y: <a> element should have an href attribute" ,
4
+ "loc" : {
5
+ "line" : 1 ,
6
+ "column" : 11
7
+ },
8
+ "pos" : 11
9
+ },
10
+ {
11
+ "message" : " A11y: '' is not a valid xlink:href attribute" ,
12
+ "loc" : {
13
+ "line" : 2 ,
14
+ "column" : 14
15
+ },
16
+ "pos" : 65
17
+ },
18
+ {
19
+ "message" : " A11y: '#' is not a valid xlink:href attribute" ,
20
+ "loc" : {
21
+ "line" : 3 ,
22
+ "column" : 14
23
+ },
24
+ "pos" : 130
25
+ }
26
+ ]
You can’t perform that action at this time.
0 commit comments