Skip to content

fix(aria): quote YAML special scalars in aria snapshot values - #41590

Closed
Spoko Dev (spokodev) wants to merge 1 commit into
microsoft:mainfrom
spokodev:w32/pw-yaml-scalars
Closed

Spoko Dev (spokodev) wants to merge 1 commit into
microsoft:mainfrom
spokodev:w32/pw-yaml-scalars

Conversation

@spokodev

Copy link
Copy Markdown

Description

yamlEscapeValueIfNeeded does not quote the YAML null indicator ~ or the special float scalars .inf / .nan, so aria snapshots corrupt when a page's accessible text or attribute is literally one of those tokens.

When such a value is emitted unquoted and then parsed back with the yaml library (YAML 1.2 core schema), the parser reinterprets it:

  • .inf -> the number Infinity, so the text silently becomes "Infinity"
  • .nan -> NaN
  • ~ -> null, which the aria snapshot parser then rejects ("value should be a string")

The same applies to .Inf, .INF, +.inf, .NaN, and so on. This breaks expect(locator).toMatchAriaSnapshot() and locator.ariaSnapshot() round-trips for a page showing, for example, .inf / .nan in a math or spreadsheet UI, or a ~ label. The existing code already quotes null, true, .5, -.inf, and similar; only this family slipped through.

Fix

// YAML null indicator and special infinity/NaN floats parse back as non-strings
if (str === '~' || /^[-+]?\.(inf|nan)$/i.test(str))
  return true;

Test

Added tests/library/unit/aria-yaml.spec.ts: these tokens round-trip back to their original strings after escaping. It fails before the change (~ -> null / parse error, .inf / .nan -> numbers) and passes after; common strings such as hello, button, path/to are not over-quoted.

The `~` null indicator and `.inf`/`.nan` floats were emitted unquoted,
so a page whose accessible text is one of these tokens produced an aria
snapshot that either failed to parse or round-tripped to a different
string (e.g. `.inf` -> `Infinity`).
@Skn0tt

Copy link
Copy Markdown
Contributor

Hi! Could you start with filing an issue about the bug you're facing? It's hard to understand the context of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants