fix(aria): fix parsing of ARIA selectors (#7037)

This commit is contained in:
Alex Rudenko 2021-04-06 10:41:49 +02:00 committed by GitHub
parent 9633e6e392
commit 4426135692
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -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 '';
}

View File

@ -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'
);
});
});