Skip to content

Commit 25bb75b

Browse files
committed
fix: template-no-invalid-aria-attributes — accept "undefined" as valid token for aria-orientation
Per aria-query 5.3.2, `aria-orientation` has `type: 'token'` with `values: ['vertical', 'undefined', 'horizontal']` — i.e. the literal string "undefined" is an explicit, valid token. Our previous implementation short-circuited on `value === 'undefined'` by returning `Boolean(attrDef.allowundefined)` before the token check. Because `aria-orientation` carries `allowundefined: false` in aria-query, the valid token "undefined" was incorrectly rejected. Fix: before applying the generic `allowundefined` shortcut, check whether the attribute is a `token`/`tokenlist` whose `values` array explicitly includes `'undefined'`. If so, the value is valid regardless of `allowundefined`. Regression tests cover the valid (`undefined`, `horizontal`) and invalid (`sideways`) cases for `aria-orientation`, in both `<template>` and hbs parsers. Reference: audit finding B9 (tests/audit/aria-props/peer-parity.js on audit/phase3/aria-props); PR #28 backlog item F1.
1 parent 24882a3 commit 25bb75b

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

lib/rules/template-no-invalid-aria-attributes.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ function isValidAriaValue(attrName, value) {
1717
return true;
1818
}
1919

20+
// Check whether 'undefined' is an explicit token in the attribute's value list
21+
// (e.g. aria-orientation allows 'undefined' per aria-query) BEFORE applying the
22+
// generic allowundefined shortcut. Otherwise valid tokens get rejected for
23+
// attributes where allowundefined is false.
24+
if (
25+
value === 'undefined' &&
26+
(attrDef.type === 'token' || attrDef.type === 'tokenlist') &&
27+
Array.isArray(attrDef.values) &&
28+
attrDef.values.includes('undefined')
29+
) {
30+
return true;
31+
}
32+
2033
if (value === 'undefined') {
2134
return Boolean(attrDef.allowundefined);
2235
}

tests/lib/rules/template-no-invalid-aria-attributes.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ ruleTester.run('template-no-invalid-aria-attributes', rule, {
3232
'<template><button type="submit" aria-disabled={{this.isDisabled}}>Submit</button></template>',
3333
'<template><div role="textbox" aria-sort={{if this.hasCustomSort "other" "ascending"}}></div></template>',
3434
'<template><div role="combobox" aria-expanded="undefined"></div></template>',
35+
'<template><div role="slider" aria-orientation="undefined"></div></template>',
36+
'<template><div role="slider" aria-orientation="horizontal"></div></template>',
3537
'<template><button aria-label={{if @isNew (t "actions.add") (t "actions.edit")}}></button></template>',
3638
],
3739
invalid: [
@@ -121,6 +123,11 @@ ruleTester.run('template-no-invalid-aria-attributes', rule, {
121123
output: null,
122124
errors: [{ messageId: 'invalidAriaAttributeValue' }],
123125
},
126+
{
127+
code: '<template><div role="slider" aria-orientation="sideways"></div></template>',
128+
output: null,
129+
errors: [{ messageId: 'invalidAriaAttributeValue' }],
130+
},
124131
],
125132
});
126133

@@ -150,6 +157,8 @@ hbsRuleTester.run('template-no-invalid-aria-attributes', rule, {
150157
'<button type="submit" aria-disabled={{this.isDisabled}}>Submit</button>',
151158
'<div role="textbox" aria-sort={{if this.hasCustomSort "other" "ascending"}}></div>',
152159
'<div role="combobox" aria-expanded="undefined"></div>',
160+
'<div role="slider" aria-orientation="undefined"></div>',
161+
'<div role="slider" aria-orientation="horizontal"></div>',
153162
'<button aria-label={{if @isNew (t "actions.add") (t "actions.edit")}}></button>',
154163
],
155164
invalid: [
@@ -223,5 +232,10 @@ hbsRuleTester.run('template-no-invalid-aria-attributes', rule, {
223232
output: null,
224233
errors: [{ messageId: 'invalidAriaAttributeValue' }],
225234
},
235+
{
236+
code: '<div role="slider" aria-orientation="sideways"></div>',
237+
output: null,
238+
errors: [{ messageId: 'invalidAriaAttributeValue' }],
239+
},
226240
],
227241
});

0 commit comments

Comments
 (0)