fix(ariaqueryhandler): allow single quotes in aria attribute selector (#7750)

This updates the regular expression used to parse aria attribute
selectors so that single quotes may be used as an alternative to double
quotes, e.g. `aria/Single button[role='button']`.

Issues: #7721

Co-authored-by: Andy Earnshaw <andy.earnshaw@gmail.com>
This commit is contained in:
Andy Earnshaw
2021-11-09 12:05:10 +00:00
committed by GitHub
parent ad7f1de44f
commit b0319ecc89
2 changed files with 10 additions and 2 deletions

View File

@@ -41,7 +41,7 @@ const normalizeValue = (value: string): string =>
value.replace(/ +/g, ' ').trim();
const knownAttributes = new Set(['name', 'role']);
const attributeRegexp =
/\[\s*(?<attribute>\w+)\s*=\s*"(?<value>\\.|[^"\\]*)"\s*\]/g;
/\[\s*(?<attribute>\w+)\s*=\s*(?<quote>"|')(?<value>\\.|.*?(?=\k<quote>))\k<quote>\s*\]/g;
/*
* The selectors consist of an accessible name to query for and optionally
@@ -58,7 +58,7 @@ function parseAriaSelector(selector: string): ariaQueryOption {
const queryOptions: ariaQueryOption = {};
const defaultName = selector.replace(
attributeRegexp,
(_, attribute: string, value: string) => {
(_, attribute: string, quote: string, value: string) => {
attribute = attribute.trim();
if (!knownAttributes.has(attribute))
throw new Error(`Unknown aria attribute "${attribute}" in selector`);