Skip to content

Commit b0319ec

Browse files
andyearnshawAndy Earnshaw
andauthored
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 <[email protected]>
1 parent ad7f1de commit b0319ec

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/common/AriaQueryHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const normalizeValue = (value: string): string =>
4141
value.replace(/ +/g, ' ').trim();
4242
const knownAttributes = new Set(['name', 'role']);
4343
const attributeRegexp =
44-
/\[\s*(?<attribute>\w+)\s*=\s*"(?<value>\\.|[^"\\]*)"\s*\]/g;
44+
/\[\s*(?<attribute>\w+)\s*=\s*(?<quote>"|')(?<value>\\.|.*?(?=\k<quote>))\k<quote>\s*\]/g;
4545

4646
/*
4747
* The selectors consist of an accessible name to query for and optionally
@@ -58,7 +58,7 @@ function parseAriaSelector(selector: string): ariaQueryOption {
5858
const queryOptions: ariaQueryOption = {};
5959
const defaultName = selector.replace(
6060
attributeRegexp,
61-
(_, attribute: string, value: string) => {
61+
(_, attribute: string, quote: string, value: string) => {
6262
attribute = attribute.trim();
6363
if (!knownAttributes.has(attribute))
6464
throw new Error(`Unknown aria attribute "${attribute}" in selector`);

test/ariaqueryhandler.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ describeChromeOnly('AriaQueryHandler', () => {
4646
'aria/Submit button and some spaces[role="button"]'
4747
);
4848
await expectFound(button);
49+
button = await page.$(
50+
"aria/Submit button and some spaces[role='button']"
51+
);
52+
await expectFound(button);
4953
button = await page.$(
5054
'aria/ Submit button and some spaces[role="button"]'
5155
);
@@ -70,6 +74,10 @@ describeChromeOnly('AriaQueryHandler', () => {
7074
'aria/[name=" Submit button and some spaces"][role="button"]'
7175
);
7276
await expectFound(button);
77+
button = await page.$(
78+
"aria/[name=' Submit button and some spaces'][role='button']"
79+
);
80+
await expectFound(button);
7381
button = await page.$(
7482
'aria/ignored[name="Submit button and some spaces"][role="button"]'
7583
);

0 commit comments

Comments
 (0)