From 3573f7a471b4474c79df9ea5c09ebe4e536eadb5 Mon Sep 17 00:00:00 2001 From: Anthony Barnes Date: Thu, 6 Oct 2016 10:13:11 +1100 Subject: [PATCH] Potential resolution for #139. Added code that filters incorrect headings into a different array if they contain partial matches. This array is used to produce a warning instead of an error prompting the user to check the validity of the table header attributes. --- HTMLCS.Util.js | 22 ++- .../Sniffs/Principle1/Guideline1_3/1_3_1.js | 9 ++ Tests/WCAG2/1_3_1_Table_Headers.html | 130 ++++++++++++++++++ 3 files changed, 156 insertions(+), 5 deletions(-) create mode 100644 Tests/WCAG2/1_3_1_Table_Headers.html diff --git a/HTMLCS.Util.js b/HTMLCS.Util.js index f03c518c..abe20119 100644 --- a/HTMLCS.Util.js +++ b/HTMLCS.Util.js @@ -797,7 +797,8 @@ _global.HTMLCS.util = function() { allowScope: true, missingThId: [], missingTd: [], - wrongHeaders: [] + wrongHeaders: [], + wrongHeadersWarning: [] } var rows = element.getElementsByTagName('tr'); @@ -923,16 +924,27 @@ _global.HTMLCS.util = function() { retval.correct = false; retval.missingTd.push(cell); } else { - actual = ' ' + actual.sort().join(' ') + ' '; - actual = actual.replace(/\s+/g, ' ').replace(/(\w+\s)\1+/g, '$1').replace(/^\s*(.*?)\s*$/g, '$1'); - if (expected !== actual) { + var textActual = ' ' + actual.sort().join(' ') + ' '; + textActual = textActual.replace(/\s+/g, ' ').replace(/(\w+\s)\1+/g, '$1').replace(/^\s*(.*?)\s*$/g, '$1'); + if (expected !== textActual) { retval.correct = false; var val = { element: cell, expected: expected, actual: (cell.getAttribute('headers') || '') } - retval.wrongHeaders.push(val); + + var partialMatches = expected.split(/\s+/).filter(function(id) { + return actual.indexOf(id) !== -1; + }); + + // If we have a partial match we want a warning to check if the header is wrong + // rather than grouping all incorrect headers together. + if (partialMatches.length >= 1) { + retval.wrongHeadersWarning.push(val); + } else { + retval.wrongHeaders.push(val); + } } }//end if }//end if diff --git a/Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_3/1_3_1.js b/Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_3/1_3_1.js index dab2f765..eade5e5f 100755 --- a/Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_3/1_3_1.js +++ b/Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_3/1_3_1.js @@ -455,6 +455,15 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_3_1_3_1 = { HTMLCS.addMessage(HTMLCS.ERROR, headersAttr.wrongHeaders[i].element, 'Incorrect headers attribute on this td element. Expected "' + headersAttr.wrongHeaders[i].expected + '" but found "' + headersAttr.wrongHeaders[i].actual + '"', 'H43.IncorrectAttr'); } + // Incorrect usage of headers - error; emit warnings. + for (var i = 0; i < headersAttr.wrongHeadersWarning.length; i++) { + HTMLCS.addMessage( + HTMLCS.WARNING, + headersAttr.wrongHeadersWarning[i].element, + 'Check headers attribute on this td element. Expected "' + headersAttr.wrongHeadersWarning[i].expected + '" but found "' + headersAttr.wrongHeadersWarning[i].actual + '"', 'H43.IncorrectAttr' + ); + } + // Errors where headers are compulsory. if ((headersAttr.required === true) && (headersAttr.allowScope === false)) { if (headersAttr.used === false) { diff --git a/Tests/WCAG2/1_3_1_Table_Headers.html b/Tests/WCAG2/1_3_1_Table_Headers.html new file mode 100644 index 00000000..b235fc00 --- /dev/null +++ b/Tests/WCAG2/1_3_1_Table_Headers.html @@ -0,0 +1,130 @@ + + + +1.3.1 Table Headers + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Order from October 25, 2015
NameQuantityCostSubtotal
Total:$86.93
Anvil1$29.95$29.95
Pseudo Tunnel4$4.25$17.00
Rocket2$19.99$39.98
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Acme Widgets For The Win
NameDescriptionPurposeCost
AnvilVery heavy block of ironSmashing the RoadRunner$29.95
RocketJet powerGo as fast as the bird$19.99
Tornado GeneratorCreate a local tornadoCreate chaos$4,590
Pseudo TunnelMake a rock look like a tunnelWatch the bird run into a rock$4.25
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Order from October 25, 2015
NameQuantityCostSubtotal
Total:$86.93
Anvil1$29.95$29.95
Pseudo Tunnel4$4.25$17.00
Rocket2$19.99$39.98
+ + +