diff --git a/lib/checks/aria/allowed-attr.js b/lib/checks/aria/allowed-attr.js index bcc8a4d5c6..63d889c5f3 100644 --- a/lib/checks/aria/allowed-attr.js +++ b/lib/checks/aria/allowed-attr.js @@ -12,12 +12,8 @@ if (!role) { allowed = axe.commons.aria.allowedAttr(role); -if (Object.keys(options).length) { - for (var roleOption in options) { - if (roleOption === role) { - allowed = axe.utils.uniqueArray(options[role].concat(allowed)); - } - } +if (Array.isArray(options[role])) { + allowed = axe.utils.uniqueArray(options[role].concat(allowed)); } if (role && allowed) { diff --git a/lib/checks/aria/required-attr.js b/lib/checks/aria/required-attr.js index 832589c329..74bce8d9ff 100644 --- a/lib/checks/aria/required-attr.js +++ b/lib/checks/aria/required-attr.js @@ -7,12 +7,8 @@ if (node.hasAttributes()) { role = node.getAttribute('role'), required = axe.commons.aria.requiredAttr(role); - if (Object.keys(options).length) { - for (var roleOption in options) { - if (roleOption === role) { - required = axe.utils.uniqueArray(options[role].concat(required)); - } - } + if (Array.isArray(options[role])) { + required = axe.utils.uniqueArray(options[role], required); } if (role && required) { for (var i = 0, l = required.length; i < l; i++) { diff --git a/lib/core/utils/to-array.js b/lib/core/utils/to-array.js index ecce937fd0..394972cd88 100644 --- a/lib/core/utils/to-array.js +++ b/lib/core/utils/to-array.js @@ -11,12 +11,13 @@ axe.utils.toArray = function (thing) { /** - * Creates an array without duplicate values - * @param {Array} arrArg Array to filter + * Creates an array without duplicate values from 2 array inputs + * @param {Array} arr1 First array + * @param {Array} arr2 Second array * @return {Array} */ -axe.utils.uniqueArray = (arrArg) => { - return arrArg.filter((elem, pos, arr) => { +axe.utils.uniqueArray = (arr1, arr2) => { + return arr1.concat(arr2).filter((elem, pos, arr) => { return arr.indexOf(elem) === pos; }); }; diff --git a/test/core/utils/to-array.js b/test/core/utils/to-array.js index 630d723bd8..133d432a8e 100644 --- a/test/core/utils/to-array.js +++ b/test/core/utils/to-array.js @@ -33,7 +33,7 @@ describe('axe.utils.uniqueArray', function () { var array1 = [1, 2, 3, 4, 5]; var array2 = [1, 3, 7]; - var result = axe.utils.uniqueArray(array1.concat(array2)); + var result = axe.utils.uniqueArray(array1, array2); assert.isArray(result); assert.includeMembers(result, [1, 2, 3, 4, 5, 7]); });