Skip to content

Fix YAML print idempotency for asterisk placeholders inside block scalars#7466

Merged
knutwannheden merged 1 commit intomainfrom
fix-yaml-asterisk-placeholder-restoration
Apr 23, 2026
Merged

Fix YAML print idempotency for asterisk placeholders inside block scalars#7466
knutwannheden merged 1 commit intomainfrom
fix-yaml-asterisk-placeholder-restoration

Conversation

@knutwannheden
Copy link
Copy Markdown
Contributor

@knutwannheden knutwannheden commented Apr 23, 2026

Motivation

  • The YAML parser pre-processes credential placeholders like password: *** REMOVED *** by swapping the captured text with a UUID before parsing (so SnakeYAML doesn't misread the asterisks as alias references), then restoring it afterward (introduced in Handle asterisk placeholder values in YAML parser #6626). The asterisk regex :\s+(\*{2,}[^\n\r]*) unintentionally matches markdown bold text inside multi-line block scalars when a colon-plus-space precedes it (for example :rotating_light: **CI Alert**: ... inside a GitHub Actions run: | script).

When that happens, the UUID ends up embedded within a long multi-line scalar value. The restoration logic on the scalar path used exact-match (Map.containsKey(scalarValue)), so it never restored the UUID and the parser reported a print-idempotency failure. This breaks parsing of otherwise valid YAML such as spring-projects/spring-ai's .github/workflows/dependency-ci-dashboard.yml.

Tightening the regex wouldn't help: credential placeholders (**REDACTED**) and markdown bold (**CI Alert**) are indistinguishable without parsing YAML structure. The fix belongs at the restoration layer.

Summary

  • Replace the exact-match containsKey(scalarValue) check with a contains / replace loop, matching how the helm-template and single-brace-template restorations already work on the same code path.
  • Add a regression test with markdown bold text inside a | block scalar, mirroring the failing case in the wild.

UUIDs are random per-parse and produced only by the parser, so substring replacement is unambiguous.

Test plan

  • New YamlParserTest.asteriskPatternInsideBlockScalar reproduces the failure on main and passes after the fix.
  • Existing YamlParserTest suite continues to pass (including asteriskPlaceholders and asteriskPlaceholdersWithAnchors).
  • Full :rewrite-yaml:test passes.

…lars

The asterisk placeholder preprocessing (introduced in #6626 to handle
credential values like `*** REMOVED ***`) replaces matched text with
UUIDs before parsing and restores them afterward. Restoration for the
variable/asterisk UUID map used exact-match against the scalar value,
so when the regex matched inside a multi-line block scalar — e.g.
markdown bold like `**CI Alert**` on a line containing `: ` from an
emoji — the UUID was embedded within a longer scalar value and never
restored, breaking print idempotency.

Align restoration with the helm and single-brace template maps on the
same code path, which already use `contains`/`replace`. UUIDs are
random per-parse and only produced by the parser, so substring
replacement is unambiguous.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Apr 23, 2026
@knutwannheden knutwannheden merged commit 8912b00 into main Apr 23, 2026
1 check passed
@knutwannheden knutwannheden deleted the fix-yaml-asterisk-placeholder-restoration branch April 23, 2026 20:52
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant