Skip to content

Commit

Permalink
fix(color-contrast): mark as needs review for text that contains only…
Browse files Browse the repository at this point in the history
… non-BMP characters (#2005)

* fix(color-contrast): mark as needs review for text that contains only non-BMP characters

* Update lib/checks/color/color-contrast.json

Co-Authored-By: Wilco Fiers <WilcoFiers@users.noreply.github.com>

Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com>
  • Loading branch information
straker and WilcoFiers committed Jan 31, 2020
1 parent 1b6ab42 commit e559be0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
15 changes: 9 additions & 6 deletions lib/checks/color/color-contrast.js
Expand Up @@ -6,14 +6,17 @@ if (!dom.isVisible(node, false)) {

const visibleText = text.visibleVirtual(virtualNode, false, true);
const ignoreUnicode = !!(options || {}).ignoreUnicode;
const textContainsOnlyUnicode = !text.removeUnicode(visibleText, {
emoji: false,
nonBmp: true,
punctuations: false
}).length;
const textContainsOnlyUnicode = !text.sanitize(
text.removeUnicode(visibleText, {
emoji: false,
nonBmp: true,
punctuations: false
})
).length;

if (textContainsOnlyUnicode && ignoreUnicode) {
return true;
this.data({ messageKey: 'nonBmp' });
return undefined;
}

const noScroll = !!(options || {}).noScroll;
Expand Down
3 changes: 2 additions & 1 deletion lib/checks/color/color-contrast.json
Expand Up @@ -22,7 +22,8 @@
"elmPartiallyObscuring": "Element's background color could not be determined because it partially overlaps other elements",
"outsideViewport": "Element's background color could not be determined because it's outside the viewport",
"equalRatio": "Element has a 1:1 contrast ratio with the background",
"shortTextContent": "Element content is too short to determine if it is actual text content"
"shortTextContent": "Element content is too short to determine if it is actual text content",
"nonBmp": "Element content contains only non-text characters"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/commons/text/unicode.js
Expand Up @@ -93,7 +93,8 @@ function getUnicodeNonBmpRegExp() {
'\u2600-\u26FF' + // Misc Symbols
'\u2700-\u27BF' + // Dingbats
'\uE000-\uF8FF' + // Private Use
']'
']',
'g'
);
}

Expand Down
11 changes: 7 additions & 4 deletions test/checks/color/color-contrast.js
Expand Up @@ -328,16 +328,19 @@ describe('color-contrast', function() {
assert.equal(checkContext._data.messageKey, 'shortTextContent');
});

it('should return undefined when the text only contains nonBmp unicode by default', function() {
it('should return undefined when the text only contains nonBmp unicode when the ignoreUnicode option is true', function() {
var params = checkSetup(
'<div style="background-color: #FFF;">' +
'<div style="color:#DDD;" id="target">◓</div>' +
'</div>'
'<div style="color:#DDD;" id="target">&#x20A0; &#x20A1; &#x20A2; &#x20A3;</div>' +
'</div>',
{
ignoreUnicode: true
}
);

var actual = contrastEvaluate.apply(checkContext, params);
assert.isUndefined(actual);
assert.equal(checkContext._data.messageKey, 'shortTextContent');
assert.equal(checkContext._data.messageKey, 'nonBmp');
});

it('should return true when the text only contains nonBmp unicode when the ignoreUnicode option is false, and there is sufficient contrast', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/commons/text/unicode.js
Expand Up @@ -160,7 +160,7 @@ describe('text.hasUnicode', function() {

describe('text.removeUnicode', function() {
it('returns string by removing non BMP unicode ', function() {
var actual = axe.commons.text.removeUnicode('₨20000', {
var actual = axe.commons.text.removeUnicode('₨20000₨₨', {
nonBmp: true
});
assert.equal(actual, '20000');
Expand Down

0 comments on commit e559be0

Please sign in to comment.