Skip to content

Commit

Permalink
fix(rules): handle roles case-insensitively
Browse files Browse the repository at this point in the history
Closes part of dequelabs#2695
  • Loading branch information
dan-tripp committed Feb 26, 2022
1 parent e0e5580 commit 53fb281
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/checks/aria/aria-errormessage-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function ariaErrormessageEvaluate(node, options, virtualNode) {
return false;
}
return (
idref.getAttribute('role') === 'alert' ||
idref.getAttribute('role')?.toLowerCase() === 'alert' ||
idref.getAttribute('aria-live') === 'assertive' ||
idref.getAttribute('aria-live') === 'polite' ||
tokenList(virtualNode.attr('aria-describedby')).indexOf(attr) > -1
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/aria/fallbackrole-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function nonePresentationOnElementWithNoImplicitRole(
* @return {Boolean} True if the element uses more than one explicit role. False otherwise.
*/
function fallbackroleEvaluate(node, options, virtualNode) {
const explicitRoles = tokenList(virtualNode.attr('role'));
const explicitRoles = tokenList(virtualNode.attr('role')?.toLowerCase());
if (explicitRoles.length <= 1) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/aria/invalidrole-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { tokenList } from '../../core/utils';
* @return {Boolean} True if the element uses an invalid role. False otherwise.
*/
function invalidroleEvaluate(node, options, virtualNode) {
const allRoles = tokenList(virtualNode.attr('role'));
const allRoles = tokenList(virtualNode.attr('role')?.toLowerCase());
const allInvalid = allRoles.every(
role => !isValidRole(role, { allowAbstract: true })
);
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/keyboard/landmark-is-top-level-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function landmarkIsTopLevelEvaluate(node) {
this.data({ role: nodeRole });

while (parent) {
var role = parent.getAttribute('role');
var role = parent.getAttribute('role')?.toLowerCase();
if (!role && parent.nodeName.toUpperCase() !== 'FORM') {
role = implicitRole(parent);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/checks/tables/th-has-data-cells-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function thHasDataCellsEvaluate(node) {
}
return (
cell.nodeName.toUpperCase() === 'TH' ||
['rowheader', 'columnheader'].indexOf(cell.getAttribute('role')) !== -1
['rowheader', 'columnheader'].indexOf(cell.getAttribute('role')?.toLowerCase()) !== -1
);
});

Expand Down
2 changes: 1 addition & 1 deletion lib/commons/aria/get-role-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import standards from '../../standards';
* @return {Mixed} String if a matching role and its type are found, otherwise `null`
*/
function getRoleType(role) {
const roleDef = standards.ariaRoles[role];
const roleDef = standards.ariaRoles[role?.toLowerCase()];

if (!roleDef) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/aria/is-unsupported-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import standards from '../../standards';
* @return {Boolean}
*/
function isUnsupportedRole(role) {
const roleDefinition = standards.ariaRoles[role];
const roleDefinition = standards.ariaRoles[role?.toLowerCase()];
return roleDefinition ? !!roleDefinition.unsupported : false;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/commons/aria/is-valid-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import isUnsupportedRole from './is-unsupported-role';
* @return {Boolean}
*/
function isValidRole(role, { allowAbstract, flagUnsupported = false } = {}) {
const roleDefinition = standards.ariaRoles[role];
const roleDefinition = standards.ariaRoles[role?.toLowerCase()];
const isRoleUnsupported = isUnsupportedRole(role);
if (!roleDefinition || (flagUnsupported && isRoleUnsupported)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/dom/is-visual-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const visualRoles = [
*/
function isVisualContent(element) {
/*eslint indent: 0*/
const role = element.getAttribute('role');
const role = element.getAttribute('role')?.toLowerCase();
if (role) {
return visualRoles.indexOf(role) !== -1;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/table/get-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import findUp from '../dom/find-up';
*/
function getScope(cell) {
var scope = cell.getAttribute('scope');
var role = cell.getAttribute('role');
var role = cell.getAttribute('role')?.toLowerCase();

if (
cell instanceof window.Element === false ||
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/table/is-data-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function isDataCell(cell) {
if (!cell.children.length && !cell.textContent.trim()) {
return false;
}
const role = cell.getAttribute('role');
const role = cell.getAttribute('role')?.toLowerCase();
if (isValidRole(role)) {
return ['cell', 'gridcell'].includes(role);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/autocomplete-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function autocompleteMatches(node, virtualNode) {

// The element has `tabindex="-1"` and has a [[semantic role]] that is
// not a [widget](https://www.w3.org/TR/wai-aria-1.1/#widget_roles)
const role = virtualNode.attr('role');
const role = virtualNode.attr('role')?.toLowerCase();
const tabIndex = virtualNode.attr('tabindex');
if (tabIndex === '-1' && role) {
const roleDef = standards.ariaRoles[role];
Expand Down
1 change: 1 addition & 0 deletions lib/rules/heading-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ function headingMatches(node) {
if (node.hasAttribute('role')) {
explicitRoles = node
.getAttribute('role')
.toLowerCase()
.split(/\s+/i)
.filter(axe.commons.aria.isValidRole);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/link-in-text-block-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isVisible, isInTextBlock } from '../commons/dom';

function linkInTextBlockMatches(node) {
var text = sanitize(node.textContent);
var role = node.getAttribute('role');
var role = node.getAttribute('role')?.toLowerCase();

if (role && role !== 'link') {
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/scrollable-region-focusable-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function scrollableRegionFocusableMatches(node, virtualNode) {
doc.querySelectorAll(`[aria-owns~="${id}"], [aria-controls~="${id}"]`)
);
const comboboxOwned = owned.some(el => {
const roles = tokenList(el.getAttribute('role'));
const roles = tokenList(el.getAttribute('role')?.toLowerCase());
return roles.includes('combobox');
});

Expand Down

0 comments on commit 53fb281

Please sign in to comment.