Fix YAML print idempotency for asterisk placeholders inside block scalars#7466
Merged
knutwannheden merged 1 commit intomainfrom Apr 23, 2026
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
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 Actionsrun: |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 asspring-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
containsKey(scalarValue)check with acontains/replaceloop, matching how the helm-template and single-brace-template restorations already work on the same code path.|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
YamlParserTest.asteriskPatternInsideBlockScalarreproduces the failure onmainand passes after the fix.YamlParserTestsuite continues to pass (includingasteriskPlaceholdersandasteriskPlaceholdersWithAnchors).:rewrite-yaml:testpasses.