diff --git a/src/validate/html/a11y.ts b/src/validate/html/a11y.ts
index 71df223d5e..4dbf249fff 100644
--- a/src/validate/html/a11y.ts
+++ b/src/validate/html/a11y.ts
@@ -106,14 +106,21 @@ export default function a11y(
}
}
+ function shouldHaveValidHref (attribute) {
+ const href = attributeMap.get(attribute);
+ const value = getStaticAttributeValue(node, attribute);
+ if (value === '' || value === '#') {
+ validator.warn(`A11y: '${value}' is not a valid ${attribute} attribute`, href.start);
+ }
+ }
+
if (node.name === 'a') {
- // anchor-is-valid
- const href = attributeMap.get('href');
if (attributeMap.has('href')) {
- const value = getStaticAttributeValue(node, 'href');
- if (value === '' || value === '#') {
- validator.warn(`A11y: '${value}' is not a valid href attribute`, href.start);
- }
+ // anchor-is-valid
+ shouldHaveValidHref('href')
+ } else if (attributeMap.has('xlink:href')) {
+ // anchor-in-svg-is-valid
+ shouldHaveValidHref('xlink:href')
} else {
validator.warn(`A11y: element should have an href attribute`, node.start);
}
diff --git a/test/validator/samples/a11y-anchor-in-svg-is-valid/input.html b/test/validator/samples/a11y-anchor-in-svg-is-valid/input.html
new file mode 100644
index 0000000000..48a5599aa2
--- /dev/null
+++ b/test/validator/samples/a11y-anchor-in-svg-is-valid/input.html
@@ -0,0 +1,3 @@
+
+
+
diff --git a/test/validator/samples/a11y-anchor-in-svg-is-valid/warnings.json b/test/validator/samples/a11y-anchor-in-svg-is-valid/warnings.json
new file mode 100644
index 0000000000..1e65bc4986
--- /dev/null
+++ b/test/validator/samples/a11y-anchor-in-svg-is-valid/warnings.json
@@ -0,0 +1,26 @@
+[
+ {
+ "message": "A11y: element should have an href attribute",
+ "loc": {
+ "line": 1,
+ "column": 11
+ },
+ "pos": 11
+ },
+ {
+ "message": "A11y: '' is not a valid xlink:href attribute",
+ "loc": {
+ "line": 2,
+ "column": 14
+ },
+ "pos": 65
+ },
+ {
+ "message": "A11y: '#' is not a valid xlink:href attribute",
+ "loc": {
+ "line": 3,
+ "column": 14
+ },
+ "pos": 130
+ }
+]