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): quote ~, .inf and .nan in aria snapshots (#43469)

Yury Semikhatsky7676475ba408
diff --git a/packages/isomorphic/yaml.ts b/packages/isomorphic/yaml.ts
index e79cf58474..7b3dec95a5 100644
--- a/packages/isomorphic/yaml.ts
+++ b/packages/isomorphic/yaml.ts
@@ -87,7 +87,11 @@ function yamlStringNeedsQuotes(str: string): boolean {
return true;
// Non-string types recognized by YAML
- if (!isNaN(Number(str)) || ['y', 'n', 'yes', 'no', 'true', 'false', 'on', 'off', 'null'].includes(str.toLowerCase()))
+ if (!isNaN(Number(str)) || ['y', 'n', 'yes', 'no', 'true', 'false', 'on', 'off', 'null', '~'].includes(str.toLowerCase()))
+ return true;
+
+ // YAML special float values: .inf, -.inf, .nan and their case variants
+ if (/^[-+]?\.(inf|nan)$/i.test(str))
return true;
return false;
diff --git a/tests/page/page-aria-snapshot.spec.ts b/tests/page/page-aria-snapshot.spec.ts
index 13b808bc39..c3bebc8d97 100644
--- a/tests/page/page-aria-snapshot.spec.ts
+++ b/tests/page/page-aria-snapshot.spec.ts
@@ -648,7 +648,9 @@ it('should escape special yaml characters', async ({ page }) => {
`);
});
-it('should escape special yaml values', async ({ page }) => {
+it('should escape special yaml values', {
+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43451' },
+}, async ({ page }) => {
await page.setContent(`
<a href="#">true</a>False
<a href="#">NO</a>yes
@@ -658,6 +660,8 @@ it('should escape special yaml values', async ({ page }) => {
<a href="#">123</a>123
<a href="#">-1.2</a>-1.2
<a href="#">-</a>-
+ <a href="#">~</a>~
+ <a href="#">.inf</a>.NaN
<input type=text value="555">
`);
@@ -686,6 +690,12 @@ it('should escape special yaml values', async ({ page }) => {
- link "-":
- /url: "#"
- text: "-"
+ - link "~":
+ - /url: "#"
+ - text: "~"
+ - link ".inf":
+ - /url: "#"
+ - text: ".NaN"
- textbox: "555"
`);
});