fix(hack): guard empty-array expansion in lint-drift for bash 3.2#117
Open
omergk28 wants to merge 1 commit into
Open
fix(hack): guard empty-array expansion in lint-drift for bash 3.2#117omergk28 wants to merge 1 commit into
omergk28 wants to merge 1 commit into
Conversation
Stock macOS ships bash 3.2 (GPLv2 freeze), which treats
"${arr[@]}" on an empty array as an unbound variable under
set -u — bash 4.4+ does not. drift_grep expands its exclude
array unconditionally and several call sites pass no excludes,
so make lint-style (and therefore make audit, the mandatory
pre-PR gate) aborted on every stock Mac before running a single
drift check.
Guard with the parameter-expansion alternate form,
${arr[@]+"${arr[@]}"}: empty expands to zero words, populated
reproduces the original quoted expansion, bash 4+ behavior
unchanged. The other hack/ array expansions are safe today
(count-guarded or hardcoded non-empty); details in the spec.
Captures the gotcha in LEARNINGS.md so the next session does
not re-debug it.
Spec: specs/fix-lint-drift-bash32-empty-array.md
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Omer Kocaoglu <omergk28@gmail.com>
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.
Summary
make audit— the contributing guide's mandatory pre-PR gate — aborts on stock macOS before running a single drift check:bash 3.2 (the newest Apple ships, frozen at the GPLv2 boundary) treats
"${arr[@]}"on an empty array as an unbound variable underset -u; bash 4.4+ does not.drift_grepexpands itsexclude_argsarray unconditionally and several call sites pass no excludes, so every macOS contributor hits this on the very first audit.Fix
Guard the expansion with the canonical parameter-expansion alternate form
${arr[@]+"${arr[@]}"}: an empty array expands to zero words, a populated array reproduces the original quoted expansion, and bash 4+ behavior is unchanged. The otherhack/array expansions were checked empirically — all safe today (count-guarded or hardcoded non-empty); details in the spec.Verification
bash hack/lint-drift.shnow exits 0.go build ./...clean.specs/fix-lint-drift-bash32-empty-array.md; the gotcha is captured inLEARNINGS.mdso the next session doesn't re-debug it.Provenance
Split out of #113 (the #93 TOCTOU fix) so each PR carries a single concern, per the contributing guide. This is an independent commit touching disjoint files (
hack/lint-drift.sh, its spec, and a LEARNINGS entry).🤖 Generated with Claude Code