Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(accessible-text-virtual): sanitize attributes on start node #1694

Merged
merged 2 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/commons/text/accessible-text-virtual.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ text.accessibleTextVirtual = function accessibleTextVirtual(

// Find the first step that returns a non-empty string
let accName = computationSteps.reduce((accName, step) => {
if (context.startNode === virtualNode) {
accName = text.sanitize(accName);
}

if (accName !== '') {
// yes, whitespace only a11y names halt the algorithm
return accName;
}
return step(virtualNode, context);
}, '');

if (context.startNode === virtualNode) {
accName = text.sanitize(accName);
}

if (context.debug) {
axe.log(accName || '{empty-value}', actualNode, context);
}
Expand Down
9 changes: 9 additions & 0 deletions test/commons/text/accessible-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,15 @@ describe('text.accessibleTextVirtual', function() {
assert.equal(axe.commons.text.accessibleTextVirtual(target), '');
});

it('should not stop when attributes contain whitespace', function() {
fixture.innerHTML =
'<button aria-label=" " aria-labelledby=" ">Hello World</button>';
axe.testUtils.flatTreeSetup(fixture);

var target = axe.utils.querySelectorAll(axe._tree, 'button')[0];
assert.equal(axe.commons.text.accessibleTextVirtual(target), 'Hello World');
});

(shadowSupport.v1 ? it : xit)(
'should only find aria-labelledby element in the same context ',
function() {
Expand Down