Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/checks/color/color-contrast.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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