Repository navigation
fix: don't treat $FOO_BAR as a placeholder for substitution FOO - #810
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
When a substitution KEY=value is provided, substitute() rejects the
stacker file if it contains the shell style placeholder $KEY, to point
users at the supported ${{KEY}} syntax. The check used
strings.Contains(content, "$KEY"), which also matches any variable
whose name merely starts with KEY. For example, building with
--substitute VERSION=1.0 failed with an "unsupported placeholder"
error for a run section using $VERSION_ID from /etc/os-release.
Only report $KEY when it is not followed by another variable name
character ([A-Za-z0-9_]). The ${KEY} checks already require an exact
key match and are unchanged.
Add test cases for variables sharing the key as a prefix, and for $KEY
followed by non-name characters, which must still be rejected. Mention
the behavior in the substitution syntax documentation.
Fixes project-stacker#809
Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
NopeCharon
requested review from
hallyn,
mikemccracken,
raharper,
rchamarthy,
rchincha,
smoser and
tych0
as code owners
October 24, 2026 19:47
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #810 +/- ##
===========================================
- Coverage 55.06% 12.94% -42.12%
===========================================
Files 55 55
Lines 5911 5924 +13
===========================================
- Hits 3255 767 -2488
- Misses 2085 5030 +2945
+ Partials 571 127 -444 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What type of PR is this?
bug
Which issue does this PR fix:
Fixes #809
What does this PR do / Why do we need it:
When a substitution
KEY=valueis provided,substitute()rejects the stacker file if it contains the shell-style placeholder$KEY. The check wasstrings.Contains(content, "$KEY"), which also matches any variable whose name just starts withKEY. As a result,stacker build --substitute VERSION=1.0failed on arunsection that uses$VERSION_IDfrom/etc/os-release:This PR reports
$KEYonly when it is not followed by another variable-name character ([A-Za-z0-9_]), using a regexp built withregexp.QuoteMeta. The${KEY}and${KEY:...}checks already require an exact key match, so they are unchanged. The substitution syntax docs now mention this behavior.If an issue # is not available please add repro steps and logs showing the issue:
See #809.
Testing done on this change:
Extended
TestSubstitute:$VERSION_ID $VERSIONS ${VERSION_ID} ${VERSIONS:-1} ${{VERSION}}withVERSION=1.0now substitutes successfully and leaves the shell variables untouched.$VERSION,$VERSION/bin,$VERSION-rc1and"$VERSION"are still rejected.Without the fix, the new case fails:
With the fix,
go test ./pkg/types/passes (on linux/arm64, using the Makefile's go-test build tags):Automation added to e2e:
No. The behavior is covered by the
TestSubstituteunit test.Will this break upgrades or downgrades?
No.
Does this PR introduce any user-facing change?:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.