From b634c343effefc871b4fb703c38a834ffaaa8846 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Mon, 30 Sep 2019 11:29:37 -0600 Subject: [PATCH] fix(label-content-name-mismatch): ignore private space unicode (#1822) * fix(label-content-name-mismatch): ignore private space unicode code characters * add test * fix test * add surrogate private use * fix comments --- lib/commons/text/unicode.js | 15 +++++++++++++++ test/checks/label/label-content-name-mismatch.js | 8 ++++++++ test/commons/text/unicode.js | 14 ++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/lib/commons/text/unicode.js b/lib/commons/text/unicode.js index 24eb8214a6..31280c5301 100644 --- a/lib/commons/text/unicode.js +++ b/lib/commons/text/unicode.js @@ -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(), ''); @@ -91,6 +92,7 @@ function getUnicodeNonBmpRegExp() { '\u25A0-\u25FF' + // Geometric Shapes '\u2600-\u26FF' + // Misc Symbols '\u2700-\u27BF' + // Dingbats + '\uE000-\uF8FF' + // Private Use ']' ); } @@ -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; +} diff --git a/test/checks/label/label-content-name-mismatch.js b/test/checks/label/label-content-name-mismatch.js index e48f3f0f82..26e2ed382f 100644 --- a/test/checks/label/label-content-name-mismatch.js +++ b/test/checks/label/label-content-name-mismatch.js @@ -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( + '' + ); + 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( '' diff --git a/test/commons/text/unicode.js b/test/commons/text/unicode.js index cf0429830b..aea08babaf 100644 --- a/test/commons/text/unicode.js +++ b/test/commons/text/unicode.js @@ -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.',