Skip to content

Handle asterisk placeholder values in YAML parser#6626

Merged
timtebeek merged 2 commits intomainfrom
handle-asterisk-yaml-placeholders
Jan 28, 2026
Merged

Handle asterisk placeholder values in YAML parser#6626
timtebeek merged 2 commits intomainfrom
handle-asterisk-yaml-placeholders

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented Jan 28, 2026

Summary

  • Add pre-processing for YAML values starting with ** (e.g., *** REMOVED ***, **REDACTED**)
  • Use the same UUID substitution strategy already in place for @variable@ and Helm templates
  • Add tests for asterisk placeholders, including a test that verifies real anchors/aliases still work

Problem

Credential placeholders like *** REMOVED *** cause SnakeYAML to interpret the leading * as an alias indicator. Since no matching anchor exists, parsing fails with an UnsupportedOperationException, and the file is returned as a ParseError.

Solution

Added ASTERISK_PLACEHOLDER_PATTERN that matches values after a colon starting with two or more asterisks. Before SnakeYAML processes the YAML, these values are replaced with UUIDs. After parsing, the original values are restored in the AST. This follows the exact same pattern already used for @variable@ placeholders.

The pattern specifically requires two or more consecutive asterisks (\*{2,}) to avoid interfering with valid single-* YAML alias references.

Test plan

  • Existing YamlParserTest tests pass

  • New asteriskPlaceholders test verifies *** REMOVED *** and **REDACTED** parse correctly

  • New asteriskPlaceholdersWithAnchors test verifies real anchors/aliases coexist with placeholders

  • Fixes moderneinc/customer-requests#1463

Values like `*** REMOVED ***` or `**REDACTED**` are used as credential
placeholders but cause SnakeYAML to interpret them as alias references,
resulting in parse failures. Apply the same UUID substitution strategy
already used for `@variable@` patterns: replace values starting with
two or more asterisks with UUIDs before parsing, then restore them
in the resulting AST.

Fixes moderneinc/customer-requests#1463
@timtebeek timtebeek merged commit 5715b70 into main Jan 28, 2026
2 checks passed
@timtebeek timtebeek deleted the handle-asterisk-yaml-placeholders branch January 28, 2026 23:41
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Jan 28, 2026
knutwannheden added a commit that referenced this pull request Apr 23, 2026
…lars (#7466)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant