Skip to content

Commit

Permalink
fix(rule): Prevent th-has-data-cells from crashing on empty rows (#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers authored Dec 20, 2018
1 parent 5e4b4cc commit 88017be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/commons/table/get-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ table.getScope = function(cell) {
var headerCol = tableGrid
.map(col => col[pos.x])
.reduce((headerCol, cell) => {
return headerCol && cell.nodeName.toUpperCase() === 'TH';
return headerCol && cell && cell.nodeName.toUpperCase() === 'TH';
}, true);

if (headerCol) {
Expand Down
11 changes: 11 additions & 0 deletions test/commons/table/get-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,15 @@ describe('table.getScope', function() {
assert.equal(axe.commons.table.getScope(target), 'row');
});
});

it('does not throw on empty rows', function() {
fixture.innerHTML =
'<table>' +
'<tr> </tr>' +
'<tr> <th id="target">foo</th> <td>bar</td> </tr>' +
'</table>';
var target = $id('target');
axe._tree = axe.utils.getFlattenedTree(fixture.firstChild);
assert.equal(axe.commons.table.getScope(target), 'auto');
});
});

0 comments on commit 88017be

Please sign in to comment.