Skip to content

Commit

Permalink
fix(accessible-text-virtual): sanitize attributes on start node (#1694)
Browse files Browse the repository at this point in the history
  • Loading branch information
straker authored and WilcoFiers committed Jul 12, 2019
1 parent 5b05eb5 commit c0bb08c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
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

0 comments on commit c0bb08c

Please sign in to comment.