From 26b99c0a511bd6fffaaca7535d732f26b39ef46e Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Mon, 10 Feb 2020 11:13:55 -0700 Subject: [PATCH] fix(color-contrast): properly pass options to check (#2033) --- lib/checks/color/color-contrast.js | 16 +++++++++------- lib/checks/color/color-contrast.json | 10 +++++----- lib/rules/color-contrast.json | 5 ----- .../rules/color-contrast/color-contrast.html | 6 ++++++ .../rules/color-contrast/color-contrast.json | 3 ++- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/checks/color/color-contrast.js b/lib/checks/color/color-contrast.js index cd3814c6c6..101888379c 100644 --- a/lib/checks/color/color-contrast.js +++ b/lib/checks/color/color-contrast.js @@ -6,13 +6,15 @@ if (!dom.isVisible(node, false)) { const visibleText = text.visibleVirtual(virtualNode, false, true); const ignoreUnicode = !!(options || {}).ignoreUnicode; -const textContainsOnlyUnicode = !text.sanitize( - text.removeUnicode(visibleText, { - emoji: false, - nonBmp: true, - punctuations: false - }) -).length; +const textContainsOnlyUnicode = + text.hasUnicode(visibleText, { + nonBmp: true + }) && + text.sanitize( + text.removeUnicode(visibleText, { + nonBmp: true + }) + ) === ''; if (textContainsOnlyUnicode && ignoreUnicode) { this.data({ messageKey: 'nonBmp' }); diff --git a/lib/checks/color/color-contrast.json b/lib/checks/color/color-contrast.json index 2ee5d60ec8..39f32c90e6 100644 --- a/lib/checks/color/color-contrast.json +++ b/lib/checks/color/color-contrast.json @@ -1,13 +1,13 @@ { "id": "color-contrast", "evaluate": "color-contrast.js", + "options": { + "noScroll": false, + "ignoreUnicode": true, + "ignoreLength": false + }, "metadata": { "impact": "serious", - "options": { - "noScroll": false, - "ignoreUnicode": true, - "ignoreLength": false - }, "messages": { "pass": "Element has sufficient color contrast of ${data.contrastRatio}", "fail": "Element has insufficient color contrast of ${data.contrastRatio} (foreground color: ${data.fgColor}, background color: ${data.bgColor}, font size: ${data.fontSize}, font weight: ${data.fontWeight}). Expected contrast ratio of ${data.expectedContrastRatio}", diff --git a/lib/rules/color-contrast.json b/lib/rules/color-contrast.json index 6213e0abee..f9f0239820 100644 --- a/lib/rules/color-contrast.json +++ b/lib/rules/color-contrast.json @@ -2,11 +2,6 @@ "id": "color-contrast", "matches": "color-contrast-matches.js", "excludeHidden": false, - "options": { - "noScroll": false, - "ignoreUnicode": true, - "ignoreLength": false - }, "tags": ["cat.color", "wcag2aa", "wcag143"], "metadata": { "description": "Ensures the contrast between foreground and background colors meets WCAG 2 AA contrast ratio thresholds", diff --git a/test/integration/rules/color-contrast/color-contrast.html b/test/integration/rules/color-contrast/color-contrast.html index 7fdd144a7b..233052f382 100644 --- a/test/integration/rules/color-contrast/color-contrast.html +++ b/test/integration/rules/color-contrast/color-contrast.html @@ -219,3 +219,9 @@ Hi + +
+
+ ₠ ₡ ₢ ₣ +
+
diff --git a/test/integration/rules/color-contrast/color-contrast.json b/test/integration/rules/color-contrast/color-contrast.json index 82b802a6a5..84d52b1292 100644 --- a/test/integration/rules/color-contrast/color-contrast.json +++ b/test/integration/rules/color-contrast/color-contrast.json @@ -30,6 +30,7 @@ ["#canttell16"], ["#canttell17"], ["#canttell18"], - ["#canttell19"] + ["#canttell19"], + ["#canttell20"] ] }