From 88017be18a3bf79527e672d6e70c6ed20b1ab257 Mon Sep 17 00:00:00 2001 From: Wilco Fiers Date: Thu, 20 Dec 2018 11:39:54 +0100 Subject: [PATCH] fix(rule): Prevent th-has-data-cells from crashing on empty rows (#1285) --- lib/commons/table/get-scope.js | 2 +- test/commons/table/get-scope.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/commons/table/get-scope.js b/lib/commons/table/get-scope.js index e97aa254b1..51b006c051 100644 --- a/lib/commons/table/get-scope.js +++ b/lib/commons/table/get-scope.js @@ -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) { diff --git a/test/commons/table/get-scope.js b/test/commons/table/get-scope.js index 20272034b0..93408f9c27 100644 --- a/test/commons/table/get-scope.js +++ b/test/commons/table/get-scope.js @@ -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 = + '' + + '' + + '' + + '
foo bar
'; + var target = $id('target'); + axe._tree = axe.utils.getFlattenedTree(fixture.firstChild); + assert.equal(axe.commons.table.getScope(target), 'auto'); + }); });