Repository navigation
fix: honor explicit empty substitution operands - #75
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The focused fix preserves existing operator semantics, with regression coverage and no unresolved findings.
No open issues 🎉
What changed in this PR
Fixes #61 by distinguishing explicit empty substitution operands from missing operands, allowing ${FOO:=} under -no-unset.
Changes:
- Initializes an empty text operand when parsing a substitution operator.
- Adds regression cases for all six operators across variable states and restriction modes.
| File | Description |
|---|---|
| parse/parse.go | Preserves explicit empty substitution operands. |
| parse/parse_test.go | Adds empty-operand regression coverage. |
Review effort: Balanced
a8m
approved these changes
Oct 18, 2026
Owner
|
Thanks for the contribution, @jihtsan. |
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.
Fixes #61.
An explicit empty operand was left as a nil node, so
${FOO:=}with-no-unsetwas evaluated like${FOO}and failed. Initialize an empty text operand when the parser reads a substitution operator; a supplied operand still replaces it normally.This covers all six existing operators without changing their documented semantics. The regression matrix covers unset, empty and non-empty variables under all four restriction modes, including preservation of
-no-emptyerrors for${EMPTY-}and${EMPTY=}. Bare variables still obey restrictions.Validation on macOS arm64:
go test -count=1 -vet=off ./...andgo test -count=1 -race -vet=off ./...pass.-no-unset, with-no-unset -fail-fast, and with-no-unset -no-empty; output isvalue:plus a newline, exit 0.gofmt -d parse/parse.go parse/parse_test.goandgit diff --checkare clean.go test ./...with vet enabled fails on both this branch and unchanged base 795eb83 at existing non-constant format strings in cmd/envsubst/main.go:36 and :100. Those lines are unchanged; tests above explicitly disable vet and do not claim that check passes. Linux, Windows and the remaining CI toolchains were not run locally.