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): better dismiss and wysiwyg symbolic text characters #4402

Merged
merged 5 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
55 changes: 37 additions & 18 deletions lib/commons/text/is-human-interpretable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,61 @@ import sanitize from './sanitize';
function isHumanInterpretable(str) {
/**
* Steps:
* 1) Check for single character edge cases
* 1) Early escape if string is empty
*
* 2) Check for single alpha character edge cases
*
* 3) Check for symbolic text character edge cases
* a) handle if character is alphanumeric & within the given icon mapping
* eg: x (close), i (info)
* eg: 'aA' for toggling capitalization
*
* 3) handle unicode from astral (non bilingual multi plane) unicode, emoji & punctuations
* 4) handle unicode from astral (non bilingual multi plane) unicode, emoji & punctuations
* eg: Windings font
* eg: '💪'
* eg: I saw a shooting 💫
* eg: ? (help), > (next arrow), < (back arrow), need help ?
*/

if (!str.length) {
if (
isEmpty(str) ||
isNonDigitCharacter(str) ||
isSymbolicText(str) ||
isUnicodeOrPunctuation(str)
) {
return 0;
}

// Step 1
const alphaNumericIconMap = [
'x', // close
'i' // info
];
// Step 1a
if (alphaNumericIconMap.includes(str)) {
return 0;
}
return 1;
}

function isEmpty(str) {
return sanitize(str).length === 0;
}

// Step 2
function isNonDigitCharacter(str) {
return str.length === 1 && !str.match(/\d/i);
gaiety-deque marked this conversation as resolved.
Show resolved Hide resolved
}

function isSymbolicText(str) {
const symbolicTextCharactersSet = new Set([
gaiety-deque marked this conversation as resolved.
Show resolved Hide resolved
// toggle capitalization
'aA',
// spelling
'abc',
'ABC'
]);

return symbolicTextCharactersSet.has(str);
}

function isUnicodeOrPunctuation(str) {
const noUnicodeStr = removeUnicode(str, {
emoji: true,
nonBmp: true,
punctuations: true
});
if (!sanitize(noUnicodeStr)) {
return 0;
}

return 1;
return !sanitize(noUnicodeStr);
}

export default isHumanInterpretable;
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
"name": "Marcy Sutton",
"organization": "Deque Systems, Inc.",
"url": "http://deque.com/"
},
{
"name": "Ava Gaiety Wroten",
"organization": "Deque Systems, Inc.",
"url": "http://deque.com/"
}
],
"homepage": "https://www.deque.com/axe/",
Expand Down
36 changes: 22 additions & 14 deletions test/commons/text/is-human-interpretable.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,71 @@
describe('text.isHumanInterpretable', function () {
it('returns 0 when given string is empty', function () {
var actual = axe.commons.text.isHumanInterpretable('');
const actual = axe.commons.text.isHumanInterpretable('');
assert.equal(actual, 0);
});

it('returns 0 when given string is a single character that is blacklisted as icon', function () {
var blacklistedIcons = ['x', 'i'];
blacklistedIcons.forEach(function (iconText) {
var actual = axe.commons.text.isHumanInterpretable(iconText);
it('returns 0 when given string is a single alpha character', function () {
const singleCharacterExamples = ['i', '×'];
gaiety-deque marked this conversation as resolved.
Show resolved Hide resolved
singleCharacterExamples.forEach(function (characterExample) {
const actual = axe.commons.text.isHumanInterpretable(characterExample);
assert.equal(actual, 0);
});
});

it('returns 0 when given string is in the symbolic text characters set (blocklist)', function () {
gaiety-deque marked this conversation as resolved.
Show resolved Hide resolved
const blocklistedSymbols = ['aA', 'abc'];
blocklistedSymbols.forEach(function (symbolicText) {
const actual = axe.commons.text.isHumanInterpretable(symbolicText);
assert.equal(actual, 0);
});
});

it('returns 0 when given string is only punctuations', function () {
var actual = axe.commons.text.isHumanInterpretable('?!!!,.');
const actual = axe.commons.text.isHumanInterpretable('?!!!,.');
assert.equal(actual, 0);
});

it('returns 1 when given string has emoji as a part of the sentence', function () {
var actual = axe.commons.text.isHumanInterpretable('I like 🏀');
const actual = axe.commons.text.isHumanInterpretable('I like 🏀');
assert.equal(actual, 1);
});

it('returns 1 when given string has non BMP character (eg: windings font) as part of the sentence', function () {
var actual = axe.commons.text.isHumanInterpretable('I ✂ my hair');
const actual = axe.commons.text.isHumanInterpretable('I ✂ my hair');
assert.equal(actual, 1);
});

it('returns 1 when given string has both non BMP character, and emoji as part of the sentence', function () {
var actual = axe.commons.text.isHumanInterpretable(
const actual = axe.commons.text.isHumanInterpretable(
'I ✂ my hair, and I like 🏀'
);
assert.equal(actual, 1);
});

it('returns 0 when given string has only emoji', function () {
var actual = axe.commons.text.isHumanInterpretable('🏀🍔🍉🎅');
const actual = axe.commons.text.isHumanInterpretable('🏀🍔🍉🎅');
assert.equal(actual, 0);
});

it('returns 0 when given string has only non BNP characters', function () {
var actual = axe.commons.text.isHumanInterpretable('⌛👓');
const actual = axe.commons.text.isHumanInterpretable('⌛👓');
assert.equal(actual, 0);
});

it('returns 0 when given string has combination of only non BNP characters and emojis', function () {
var actual = axe.commons.text.isHumanInterpretable('⌛👓🏀🍔🍉🎅');
const actual = axe.commons.text.isHumanInterpretable('⌛👓🏀🍔🍉🎅');
assert.equal(actual, 0);
});

it('returns 1 when given string is a punctuated sentence', function () {
var actual = axe.commons.text.isHumanInterpretable(
const actual = axe.commons.text.isHumanInterpretable(
"I like football, but I prefer basketball; although I can't play either very well."
);
assert.equal(actual, 1);
});

it('returns 1 for a sentence without emoji or punctuations', function () {
var actual = axe.commons.text.isHumanInterpretable('Earth is round');
const actual = axe.commons.text.isHumanInterpretable('Earth is round');
assert.equal(actual, 1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
<button id="incomplete9" aria-label="help">?</button>
<button id="incomplete10" aria-label="&#x1F354;">&#x1F354;</button>
<button id="incomplete11" aria-label="close">&#10060;</button>
<button id="incomplete12" aria-label="close">×</button>
gaiety-deque marked this conversation as resolved.
Show resolved Hide resolved
<button id="incomplete13" aria-label="close">i</button>
<button id="incomplete14" aria-label="close">B</button>
<button id="incomplete15" aria-label="close">ABC</button>
<button id="incomplete16" aria-label="close">aA</button>

<!-- inapplicable -->
<a id="inapplicable1" aria-label="OK">Next</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
["#incomplete8"],
["#incomplete9"],
["#incomplete10"],
["#incomplete11"]
["#incomplete11"],
["#incomplete12"],
["#incomplete13"],
["#incomplete14"],
["#incomplete15"],
["#incomplete16"]
]
}
Loading