From 6505a3e34cc9e2dad8e55c6b5bc713710ded5d14 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 19 Dec 2024 12:46:54 -0800 Subject: [PATCH] fix(yaml): escape to disambiguate yaml arrays (#34096) --- packages/playwright-core/src/server/injected/yaml.ts | 4 ++++ tests/page/page-aria-snapshot.spec.ts | 2 ++ 2 files changed, 6 insertions(+) diff --git a/packages/playwright-core/src/server/injected/yaml.ts b/packages/playwright-core/src/server/injected/yaml.ts index 7daebc574a..a9365c15bd 100644 --- a/packages/playwright-core/src/server/injected/yaml.ts +++ b/packages/playwright-core/src/server/injected/yaml.ts @@ -82,6 +82,10 @@ function yamlStringNeedsQuotes(str: string): boolean { if (/[{}`]/.test(str)) return true; + // YAML array starts with [ + if (/^\[/.test(str)) + return true; + // Non-string types recognized by YAML if (!isNaN(Number(str)) || ['y', 'n', 'yes', 'no', 'true', 'false', 'on', 'off', 'null'].includes(str.toLowerCase())) return true; diff --git a/tests/page/page-aria-snapshot.spec.ts b/tests/page/page-aria-snapshot.spec.ts index 77dc45a01e..1dafe14fa7 100644 --- a/tests/page/page-aria-snapshot.spec.ts +++ b/tests/page/page-aria-snapshot.spec.ts @@ -482,6 +482,7 @@ it('should escape yaml text in text nodes', async ({ page }) => { {four} [five] +
[Select all]
`); await checkAndMatchSnapshot(page.locator('body'), ` @@ -504,6 +505,7 @@ it('should escape yaml text in text nodes', async ({ page }) => { - text: "} [" - link "five" - text: "]" + - text: "[Select all]" `); });