Skip to content

Commit

Permalink
fix: prevent TypeErrors in color-contrast checks (#1320)
Browse files Browse the repository at this point in the history
This patch adds a safeguard to `color.filteredRectStack` which prevents a `TypeError: Cannot read property '0' of undefined` from being thrown.

This is not a perfect solution, but a stop-gap instead. It's still unclear why we're getting `undefined` here. More investigation is needed, but this can happen at a later date.

Closes #1306 and #1259.
  • Loading branch information
stephenmathieson committed Jan 17, 2019
1 parent 5c3280f commit a34165c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/commons/color/get-background-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ color.filteredRectStack = function(elm) {
let rectA = rectStack[index - 1],
rectB = rectStack[index];

// If either rect are undefined, we cannot complete the test. We exit
// early to avoid unhelpful errors.
// See https://github.com/dequelabs/axe-core/issues/1306.
if (rectA === undefined || rectB === undefined) {
isSame = false;
return;
}

// if elements in clientRects are the same
// or the boundingClientRect contains the differing element, pass it
isSame =
Expand Down

0 comments on commit a34165c

Please sign in to comment.