fix: guard empty array expansion for bash 3.2 compatibility#791
Closed
tairosonloa wants to merge 2 commits intotw93:mainfrom
Closed
fix: guard empty array expansion for bash 3.2 compatibility#791tairosonloa wants to merge 2 commits intotw93:mainfrom
tairosonloa wants to merge 2 commits intotw93:mainfrom
Conversation
macOS ships with bash 3.2, which raises "unbound variable" under `set -u`
when expanding an empty array with `"${array[@]}"`, even if the array was
declared with `local -a array=()`. Use the `${array[@]+"${array[@]}"}` idiom
so the expansion is skipped safely when `mapped_app_bundles` is empty.
Related with tw93#790
Adds a test that exercises the empty mapped_app_bundles array expansion under set -euo pipefail with multiple apps to scan, asserting a clean exit status 1 instead of crashing with "unbound variable" in bash 3.2.
Owner
|
@tairosonloa thanks for catching this fast and including a regression test. There was an overlapping PR (#792) using the explicit Closing this PR. The fix will ship in the next release; you can run |
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
macOS ships with bash 3.2, which raises "unbound variable" under
set -uwhen expanding an empty array with"${array[@]}", even if the array was declared withlocal -a array=().This PR uses the
${array[@]+"${array[@]}"}idiom so the expansion is skipped safely whenmapped_app_bundlesis empty.Fixes: #790
Safety Review
Yes, as it fixes an issue with
mo cleanNo
N/A
Tests
I ran the related test suite with
bats tests/bundle_resolver.batsN/A, but I tested to run the
mo cleanagain on my MacBook and the error is now gone.Safety-related changes