diff --git a/lib/rules/template-no-invalid-aria-attributes.js b/lib/rules/template-no-invalid-aria-attributes.js index 4a5c7a2a48..302c8267a7 100644 --- a/lib/rules/template-no-invalid-aria-attributes.js +++ b/lib/rules/template-no-invalid-aria-attributes.js @@ -11,16 +11,7 @@ function isNumeric(value) { return !Number.isNaN(Number(value)); } -function isValidAriaValue(attrName, value) { - const attrDef = aria.get(attrName); - if (!attrDef) { - return true; - } - - if (value === 'undefined') { - return Boolean(attrDef.allowundefined); - } - +function validateByType(attrDef, value) { switch (attrDef.type) { case 'boolean': { return isBoolean(value); @@ -60,6 +51,32 @@ function isValidAriaValue(attrName, value) { } } +function isValidAriaValue(attrName, value) { + const attrDef = aria.get(attrName); + if (!attrDef) { + return true; + } + + // Check whether 'undefined' is an explicit token in the attribute's value list + // (e.g. aria-orientation allows 'undefined' per aria-query) BEFORE applying the + // generic allowundefined shortcut. Otherwise valid tokens get rejected for + // attributes where allowundefined is false. + if ( + value === 'undefined' && + (attrDef.type === 'token' || attrDef.type === 'tokenlist') && + Array.isArray(attrDef.values) && + attrDef.values.includes('undefined') + ) { + return true; + } + + if (value === 'undefined') { + return Boolean(attrDef.allowundefined); + } + + return validateByType(attrDef, value); +} + function getExpectedTypeDescription(attrName) { const attrDef = aria.get(attrName); if (!attrDef) { diff --git a/tests/lib/rules/template-no-invalid-aria-attributes.js b/tests/lib/rules/template-no-invalid-aria-attributes.js index 7f8e10b8e6..aefa9d0cd9 100644 --- a/tests/lib/rules/template-no-invalid-aria-attributes.js +++ b/tests/lib/rules/template-no-invalid-aria-attributes.js @@ -32,6 +32,8 @@ ruleTester.run('template-no-invalid-aria-attributes', rule, { '', '', '', + '', + '', '', ], invalid: [ @@ -121,6 +123,11 @@ ruleTester.run('template-no-invalid-aria-attributes', rule, { output: null, errors: [{ messageId: 'invalidAriaAttributeValue' }], }, + { + code: '', + output: null, + errors: [{ messageId: 'invalidAriaAttributeValue' }], + }, ], }); @@ -150,6 +157,8 @@ hbsRuleTester.run('template-no-invalid-aria-attributes', rule, { '', '
', '', + '', + '', '', ], invalid: [ @@ -223,5 +232,10 @@ hbsRuleTester.run('template-no-invalid-aria-attributes', rule, { output: null, errors: [{ messageId: 'invalidAriaAttributeValue' }], }, + { + code: '', + output: null, + errors: [{ messageId: 'invalidAriaAttributeValue' }], + }, ], });