From d83aa9aba9679d7c57849bde05fe9fb69015429f Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Tue, 30 Mar 2021 13:56:08 +0200 Subject: [PATCH] fix(aria): fix parsing of ARIA selectors --- 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 ffbe89444605c..9d8cf964a7c3e 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 f38e7e7694878..fcc3eef7a415f 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' + ); }); });