Skip to content

Commit 223a4bc

Browse files
authored
fix(color-contrast): ignore nodes that don't contain text (#1837)
1 parent 8df4fb5 commit 223a4bc

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/rules/color-contrast-matches.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,15 @@ if (node.getAttribute('id')) {
9393
}
9494
}
9595

96-
if (axe.commons.text.visibleVirtual(virtualNode, false, true) === '') {
96+
const visibleText = axe.commons.text.visibleVirtual(virtualNode, false, true);
97+
if (
98+
visibleText === '' ||
99+
axe.commons.text.removeUnicode(visibleText, {
100+
emoji: true,
101+
nonBmp: true,
102+
punctuations: true
103+
}) === ''
104+
) {
97105
return false;
98106
}
99107

test/rule-matches/color-contrast-matches.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,33 @@ describe('color-contrast-matches', function() {
3939
assert.isTrue(rule.matches(target, axe.utils.getNodeFromTree(target)));
4040
});
4141

42+
it('should not match when text only contains emoji', function() {
43+
fixture.innerHTML =
44+
'<div style="color: yellow; background-color: white;" id="target">' +
45+
'🌎</div>';
46+
var target = fixture.querySelector('#target');
47+
axe.testUtils.flatTreeSetup(fixture);
48+
assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(target)));
49+
});
50+
51+
it('should not match when text only contains punctuation', function() {
52+
fixture.innerHTML =
53+
'<div style="color: yellow; background-color: white;" id="target">' +
54+
'&rlm;</div>';
55+
var target = fixture.querySelector('#target');
56+
axe.testUtils.flatTreeSetup(fixture);
57+
assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(target)));
58+
});
59+
60+
it('should not match when text only contains nonBmp unicode', function() {
61+
fixture.innerHTML =
62+
'<div style="color: yellow; background-color: white;" id="target">' +
63+
'◓</div>';
64+
var target = fixture.querySelector('#target');
65+
axe.testUtils.flatTreeSetup(fixture);
66+
assert.isFalse(rule.matches(target, axe.utils.getNodeFromTree(target)));
67+
});
68+
4269
it('should not match when there is text that is out of the container', function() {
4370
fixture.innerHTML =
4471
'<div style="color: yellow; text-indent: -9999px; background-color: white;" id="target">' +

0 commit comments

Comments
 (0)