Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(aria-snapshot): quote names that only look like regexes (#42811)

AbNoZ&v024afcfb174caf
diff --git a/packages/isomorphic/ariaSnapshotRenderer.ts b/packages/isomorphic/ariaSnapshotRenderer.ts
index cc0cf073a4..1e0f62e392 100644
--- a/packages/isomorphic/ariaSnapshotRenderer.ts
+++ b/packages/isomorphic/ariaSnapshotRenderer.ts
@@ -41,8 +41,9 @@ export function renderAriaSnapshotAsYaml(snapshot: AriaSnapshotJSON, options: Ar
if (node.name && node.name.length <= 900) {
const name = renderString(node.name);
if (name) {
- const stringifiedName = name.startsWith('/') && name.endsWith('/') ? name : JSON.stringify(name);
- key += ' ' + stringifiedName;
+ // Only a name that was actually converted to a regex may be left unquoted.
+ const isRegex = options.convertStringsToRegex && name !== node.name;
+ key += ' ' + (isRegex ? name : JSON.stringify(name));
}
}
if (node.checked === 'mixed')
diff --git a/tests/page/page-aria-snapshot.spec.ts b/tests/page/page-aria-snapshot.spec.ts
index 7cb41c8881..a96ce4e4d5 100644
--- a/tests/page/page-aria-snapshot.spec.ts
+++ b/tests/page/page-aria-snapshot.spec.ts
@@ -55,6 +55,25 @@ it('should snapshot list with accessible name', async ({ page }) => {
`);
});
+it('should quote names that look like regexes', async ({ page }) => {
+ await page.setContent(`
+ <nav>
+ <a href="/">/</a>
+ <a href="/docs/">/docs/</a>
+ <a href="/a(b/">/a(b/</a>
+ </nav>
+ `);
+ await checkAndMatchSnapshot(page.locator('nav'), `
+ - navigation:
+ - link "/":
+ - /url: /
+ - link "/docs/":
+ - /url: /docs/
+ - link "/a(b/":
+ - /url: /a(b/
+ `);
+});
+
it('should snapshot complex', async ({ page }) => {
await page.setContent(`
<ul>