fix(aria): fix parsing of ARIA selectors (#7037)
This commit is contained in:
parent
9633e6e392
commit
4426135692
@ -52,15 +52,13 @@ function parseAriaSelector(selector: string): ariaQueryOption {
|
|||||||
const normalize = (value: string): string => value.replace(/ +/g, ' ').trim();
|
const normalize = (value: string): string => value.replace(/ +/g, ' ').trim();
|
||||||
const knownAttributes = new Set(['name', 'role']);
|
const knownAttributes = new Set(['name', 'role']);
|
||||||
const queryOptions: ariaQueryOption = {};
|
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(
|
const defaultName = selector.replace(
|
||||||
attributeRegexp,
|
attributeRegexp,
|
||||||
(_, attribute: string, value: string) => {
|
(_, attribute: string, value: string) => {
|
||||||
attribute = attribute.trim();
|
attribute = attribute.trim();
|
||||||
if (!knownAttributes.has(attribute))
|
if (!knownAttributes.has(attribute))
|
||||||
throw new Error(
|
throw new Error(`Unknown aria attribute "${attribute}" in selector`);
|
||||||
'Unknown aria attribute "${groups.attribute}" in selector'
|
|
||||||
);
|
|
||||||
queryOptions[attribute] = normalize(value);
|
queryOptions[attribute] = normalize(value);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,9 @@ describeChromeOnly('AriaQueryHandler', () => {
|
|||||||
'aria/ignored[name="Submit button and some spaces"][role="button"]'
|
'aria/ignored[name="Submit button and some spaces"][role="button"]'
|
||||||
);
|
);
|
||||||
await expectFound(button);
|
await expectFound(button);
|
||||||
|
await expect(page.$('aria/smth[smth="true"]')).rejects.toThrow(
|
||||||
|
'Unknown aria attribute "smth" in selector'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user