From 0b0fec285d7df8675c8f5ecc42519f3734d70f72 Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Fri, 8 Jan 2021 09:48:17 -0700 Subject: [PATCH] fix(color-contrast-matches): do not pass empty string to getElementById (#2739) --- lib/rules/color-contrast-matches.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/rules/color-contrast-matches.js b/lib/rules/color-contrast-matches.js index c3d922241b..f6f12ec47d 100644 --- a/lib/rules/color-contrast-matches.js +++ b/lib/rules/color-contrast-matches.js @@ -69,14 +69,17 @@ function colorContrastMatches(node, virtualNode) { : virtualNode; // explicit label of disabled control - const doc = getRootNode(labelNode); - const explicitControl = doc.getElementById(labelNode.htmlFor || ''); - const explicitControlVirtual = - explicitControl && getNodeFromTree(explicitControl); + if (labelNode.htmlFor) { + const doc = getRootNode(labelNode); + const explicitControl = doc.getElementById(labelNode.htmlFor); + const explicitControlVirtual = + explicitControl && getNodeFromTree(explicitControl); - if (explicitControlVirtual && isDisabled(explicitControlVirtual)) { - return false; + if (explicitControlVirtual && isDisabled(explicitControlVirtual)) { + return false; + } } + // implicit label of disabled control const query = 'input:not([type="hidden"]):not([type="image"])' +