From 4426135692ae3ee7ed2841569dd9375e7ca8286c Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Tue, 6 Apr 2021 10:41:49 +0200 Subject: [PATCH] fix(aria): fix parsing of ARIA selectors (#7037) --- src/common/AriaQueryHandler.ts | 6 ++---- test/ariaqueryhandler.spec.ts | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/common/AriaQueryHandler.ts b/src/common/AriaQueryHandler.ts index ffbe8944..9d8cf964 100644 --- a/src/common/AriaQueryHandler.ts +++ b/src/common/AriaQueryHandler.ts @@ -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*(?\w+)\s*=\s*"(?\\.|[^"\\]*)"\s*\]/; + const attributeRegexp = /\[\s*(?\w+)\s*=\s*"(?\\.|[^"\\]*)"\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 ''; } diff --git a/test/ariaqueryhandler.spec.ts b/test/ariaqueryhandler.spec.ts index f38e7e76..fcc3eef7 100644 --- a/test/ariaqueryhandler.spec.ts +++ b/test/ariaqueryhandler.spec.ts @@ -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' + ); }); });