Skip to content

Commit

Permalink
fix(label-content-name-mismatch): ignore private space unicode (#1822)
Browse files Browse the repository at this point in the history
* fix(label-content-name-mismatch): ignore private space unicode code characters

* add test

* fix test

* add surrogate private use

* fix comments
  • Loading branch information
straker committed Sep 30, 2019
1 parent 15f5d2d commit b634c34
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
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
']'
);
}
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

0 comments on commit b634c34

Please sign in to comment.