diff --git a/doc/rule-descriptions.md b/doc/rule-descriptions.md index 2645ea3612..65a042e4f5 100644 --- a/doc/rule-descriptions.md +++ b/doc/rule-descriptions.md @@ -111,7 +111,7 @@ Rules that do not necessarily conform to WCAG success criterion but are industry | [scope-attr-valid](https://dequeuniversity.com/rules/axe/4.4/scope-attr-valid?application=RuleDescription) | Ensures the scope attribute is used correctly on tables | Moderate, Critical | cat.tables, best-practice | failure | | | [skip-link](https://dequeuniversity.com/rules/axe/4.4/skip-link?application=RuleDescription) | Ensure all skip links have a focusable target | Moderate | cat.keyboard, best-practice | failure, needs review | | | [tabindex](https://dequeuniversity.com/rules/axe/4.4/tabindex?application=RuleDescription) | Ensures tabindex attribute values are not greater than 0 | Serious | cat.keyboard, best-practice | failure | | -| [table-duplicate-name](https://dequeuniversity.com/rules/axe/4.4/table-duplicate-name?application=RuleDescription) | Ensure the <caption> element does not contain the same text as the summary attribute | Minor | cat.tables, best-practice | failure | | +| [table-duplicate-name](https://dequeuniversity.com/rules/axe/4.4/table-duplicate-name?application=RuleDescription) | Ensure the <caption> element does not contain the same text as the summary attribute | Minor | cat.tables, best-practice | failure, needs review | | ## WCAG 2.0 and 2.1 level AAA rules diff --git a/lib/checks/tables/same-caption-summary-evaluate.js b/lib/checks/tables/same-caption-summary-evaluate.js index 649372925f..6aafd3f087 100644 --- a/lib/checks/tables/same-caption-summary-evaluate.js +++ b/lib/checks/tables/same-caption-summary-evaluate.js @@ -1,12 +1,23 @@ -import { accessibleText } from '../../commons/text'; - -function sameCaptionSummaryEvaluate(node) { - // passing node.caption to accessibleText instead of using - // the logic in accessibleTextVirtual on virtualNode - return ( - !!(node.summary && node.caption) && - node.summary.toLowerCase() === accessibleText(node.caption).toLowerCase() - ); -} +import { sanitize, subtreeText } from '../../commons/text'; export default sameCaptionSummaryEvaluate; + +function sameCaptionSummaryEvaluate(node, options, virtualNode) { + if (virtualNode.children === undefined) { + return undefined; + } + + var summary = virtualNode.attr('summary'); + var captionNode = virtualNode.children.find(isCaptionNode); + var caption = captionNode ? sanitize(subtreeText(captionNode)) : false; + + if (!caption || !summary) { + return false; + } + + return sanitize(summary).toLowerCase() === sanitize(caption).toLowerCase(); +} + +function isCaptionNode(virtualNode) { + return virtualNode.props.nodeName === 'caption'; +} diff --git a/lib/checks/tables/same-caption-summary.json b/lib/checks/tables/same-caption-summary.json index e7bd484fa1..04b8bee95f 100644 --- a/lib/checks/tables/same-caption-summary.json +++ b/lib/checks/tables/same-caption-summary.json @@ -5,7 +5,8 @@ "impact": "minor", "messages": { "pass": "Content of summary attribute and