Skip to content

Commit

Permalink
fix(aria): fix parsing of ARIA selectors (#7037)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Apr 6, 2021
1 parent 9633e6e commit 4426135
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/common/AriaQueryHandler.ts
Expand Up @@ -52,15 +52,13 @@ function parseAriaSelector(selector: string): ariaQueryOption {
const normalize = (value: string): string => value.replace(/ +/g, ' ').trim();
const knownAttributes = new Set(['name', 'role']);
const queryOptions: ariaQueryOption = {};
const attributeRegexp = /\[\s*(?<attribute>\w+)\s*=\s*"(?<value>\\.|[^"\\]*)"\s*\]/;
const attributeRegexp = /\[\s*(?<attribute>\w+)\s*=\s*"(?<value>\\.|[^"\\]*)"\s*\]/g;
const defaultName = selector.replace(
attributeRegexp,
(_, attribute: string, value: string) => {
attribute = attribute.trim();
if (!knownAttributes.has(attribute))
throw new Error(
'Unknown aria attribute "${groups.attribute}" in selector'
);
throw new Error(`Unknown aria attribute "${attribute}" in selector`);
queryOptions[attribute] = normalize(value);
return '';
}
Expand Down
3 changes: 3 additions & 0 deletions test/ariaqueryhandler.spec.ts
Expand Up @@ -74,6 +74,9 @@ describeChromeOnly('AriaQueryHandler', () => {
'aria/ignored[name="Submit button and some spaces"][role="button"]'
);
await expectFound(button);
await expect(page.$('aria/smth[smth="true"]')).rejects.toThrow(
'Unknown aria attribute "smth" in selector'
);
});
});

Expand Down

0 comments on commit 4426135

Please sign in to comment.