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(label-content-name-mismatch): ignore private space unicode #1822

Merged
merged 5 commits into from
Sep 30, 2019
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: 15 additions & 0 deletions lib/commons/text/unicode.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ text.removeUnicode = function removeUnicode(str, options) {
}
if (nonBmp) {
str = str.replace(getUnicodeNonBmpRegExp(), '');
str = str.replace(getSupplementaryPrivateUseRegExp(), '');
}
if (punctuations) {
str = str.replace(getPunctuationRegExp(), '');
Expand Down Expand Up @@ -91,6 +92,7 @@ function getUnicodeNonBmpRegExp() {
'\u25A0-\u25FF' + // Geometric Shapes
'\u2600-\u26FF' + // Misc Symbols
'\u2700-\u27BF' + // Dingbats
'\uE000-\uF8FF' + // Private Use
straker marked this conversation as resolved.
Show resolved Hide resolved
']'
);
}
Expand All @@ -115,3 +117,16 @@ function getPunctuationRegExp() {
*/
return /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g;
}

/**
* Get regular expression for supplementary private use
*
* @returns {RegExp}
*/
function getSupplementaryPrivateUseRegExp() {
/**
* Reference: https://www.unicode.org/charts/PDF/UD800.pdf
* https://www.unicode.org/charts/PDF/UDC00.pdf
*/
return /[\uDB80-\uDBBF][\uDC00-\uDFFD]/g;
}
8 changes: 8 additions & 0 deletions test/checks/label/label-content-name-mismatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ describe('label-content-name-mismatch tests', function() {
assert.isTrue(actual);
});

it('returns true when visible text excluding private use unicode is part of accessible name', function() {
var vNode = queryFixture(
'<button id="target" aria-label="Favorites"> Favorites</button>'
);
var actual = check.evaluate(vNode.actualNode, options, vNode);
assert.isTrue(actual);
});

it('returns undefined (needs review) when visible text name is only an emoji', function() {
var vNode = queryFixture(
'<button id="target" aria-label="comet">☄️</button>'
Expand Down
14 changes: 14 additions & 0 deletions test/commons/text/unicode.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ describe('text.removeUnicode', function() {
assert.equal(actual, '');
});

it('returns string removing all private use unicode', function() {
var actual = axe.commons.text.removeUnicode('', {
nonBmp: true
});
assert.equal(actual, '');
});

it('returns string removing all supplementary private use unicode', function() {
var actual = axe.commons.text.removeUnicode('󰀀󿰀󿿽󰏽', {
nonBmp: true
});
assert.equal(actual, '');
});

it('returns string removing combination of unicode characters', function() {
var actual = axe.commons.text.removeUnicode(
'The ☀️ is orange, the ◓ is white.',
Expand Down