Skip to content

template: preserve replacement config for nested substitutions#861

Open
WyRainBow wants to merge 2 commits into
compose-spec:mainfrom
WyRainBow:codex/fix-replacementfunc-recursion-856
Open

template: preserve replacement config for nested substitutions#861
WyRainBow wants to merge 2 commits into
compose-spec:mainfrom
WyRainBow:codex/fix-replacementfunc-recursion-856

Conversation

@WyRainBow
Copy link
Copy Markdown

@WyRainBow WyRainBow commented Apr 6, 2026

Summary

Preserve interpolation config when recursively substituting the rest portion of braced expressions in DefaultReplacementAppliedFunc.

Before this change, the recursive call used SubstituteWith(rest, mapping, pattern), which dropped caller-provided options such as custom ReplacementFunc and WithoutLogging. This caused mixed expressions like ${FILE:-...} ${ENTRY_ID} to incorrectly process ${ENTRY_ID} with default behavior.

What changed

  • Pass the current config context to nested substitution by using SubstituteWithOptions with:
    • WithPattern(cfg.pattern)
    • WithReplacementFunction(cfg.replacementFunc) when set
    • WithSubstitutionFunction(cfg.substituteFunc) when set
    • WithoutLogging when logging is disabled

Verification

  • go test ./template -count=1
  • go test ./... -count=1

Fixes #856

Signed-off-by: wyRainBow <weiyu9484@gmail.com>
Signed-off-by: wyRainBow <weiyu9484@gmail.com>
@WyRainBow WyRainBow force-pushed the codex/fix-replacementfunc-recursion-856 branch from 69f14dd to e9ae694 Compare April 6, 2026 17:07
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.

Custom ReplacementFunc not preserved when processing nested substitutions

1 participant