From 38277699f8e9617b5fbb533bce2e4ef36fb4bda5 Mon Sep 17 00:00:00 2001 From: "Abnoz.v2" Date: Sun, 20 Sep 2026 11:26:36 +0100 Subject: [PATCH] fix(aria-snapshot): quote names that only look like regexes The renderer left any name that starts and ends with "/" unquoted, assuming it was a generated regex. That also applied when regex conversion was off, so a literal name such as "/" produced a snapshot the parser rejects with "Unterminated regex". Fixes https://github.com/microsoft/playwright/issues/42807 --- packages/isomorphic/ariaSnapshotRenderer.ts | 5 +++-- tests/page/page-aria-snapshot.spec.ts | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/isomorphic/ariaSnapshotRenderer.ts b/packages/isomorphic/ariaSnapshotRenderer.ts index cc0cf073a4ada..1e0f62e392ffb 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 7cb41c8881620..a96ce4e4d5e9d 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(` + + `); + 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(`