Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(activate): guard bash chpwd hook under nounset#9716

Merged
jdx merged 1 commit into
jdx:mainfrom
risu729:fix/bash-chpwd-nounset
May 10, 2026
Merged

fix(activate): guard bash chpwd hook under nounset#9716
jdx merged 1 commit into
jdx:mainfrom
risu729:fix/bash-chpwd-nounset

Conversation

@risu729

@risu729 risu729 commented May 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Guard bash's zsh-like chpwd_functions array expansion with the same nounset-safe pattern used for __MISE_FLAGS.
  • Update the bash activation snapshot.
  • Add a focused bash e2e covering cd with chpwd_functions unset under set -u.

Test plan

  • shellcheck src/assets/bash_zsh_support/chpwd/function.sh e2e/env/test_bash_chpwd_functions_nounset
  • bash --noprofile --norc -euo pipefail e2e/env/test_bash_chpwd_functions_nounset
  • git diff --check
  • docker run --rm bash:3.2 ... reproduces the old chpwd_functions[@]: unbound variable failure
  • docker run --rm -v "$PWD:/work:ro" -w /work bash:3.2 ... verifies the patched hook succeeds under Bash 3.2 nounset
  • docker run --rm bash:3.2 ... verifies array entries with spaces remain separate words

Fixes #9658

Note: This PR description was generated by an AI coding assistant.

@risu729

risu729 commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

Self-review completed after opening the draft PR.

I re-read the PR diff and checked the bash expansion behavior on Bash 3.2 for the affected states:

  • original expansion fails with chpwd_functions[@]: unbound variable under set -u
  • patched expansion succeeds when chpwd_functions is unset
  • patched expansion succeeds when chpwd_functions is declared but empty
  • patched expansion succeeds when chpwd_functions=()
  • patched expansion preserves entries containing spaces as single hook names

I did not find any changes needed from self-review.

Note: This comment was generated by an AI coding assistant.

@greptile-apps

greptile-apps Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes a bash crash under set -u when chpwd_functions is unset by applying the same nounset-safe array expansion idiom (${arr[@]+"${arr[@]}"}) already used for __MISE_FLAGS elsewhere in the activation script.

  • src/assets/bash_zsh_support/chpwd/function.sh: replaces "${chpwd_functions[@]}" with ${chpwd_functions[@]+"${chpwd_functions[@]}"}, which expands to nothing when the array is unset rather than triggering an unbound variable error.
  • e2e/env/test_bash_chpwd_functions_nounset: adds a focused end-to-end test that activates mise, unsets chpwd_functions, and calls cd . under set -euo pipefail to reproduce and verify the fix.
  • Snapshot: updated to match the new expansion in function.sh.

Confidence Score: 5/5

Safe to merge β€” the one-line change is a well-known bash idiom that is correct for unset, empty-array, and populated-array cases, and the new e2e test directly covers the reported failure scenario.

The change is minimal and targeted: a single substitution in one shell function, backed by an automated e2e test that exercises the exact failure path. The idiom is the canonical nounset-safe pattern for bash arrays and behaves correctly across all three states of chpwd_functions (unset, empty, non-empty). The snapshot update is mechanical.

No files require special attention.

Important Files Changed

Filename Overview
src/assets/bash_zsh_support/chpwd/function.sh Applies the standard nounset-safe array expansion idiom to guard against chpwd_functions being unset when bash runs under set -u.
e2e/env/test_bash_chpwd_functions_nounset New e2e test that activates mise in bash, unsets chpwd_functions, then runs cd . to confirm no unbound variable error under set -euo pipefail.
src/shell/snapshots/mise__shell__bash__tests__activate.snap Snapshot updated to reflect the same nounset-safe expansion change; no other lines altered.

Reviews (1): Last reviewed commit: "fix(activate): guard bash chpwd hook und..." | Re-trigger Greptile

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes a bug where the Bash cd wrapper would fail when the nounset option (set -u) is enabled and the chpwd_functions array is unset. The fix implements a safer array expansion syntax in the shell support scripts and includes a new E2E test to prevent regressions. I have no feedback to provide as there were no review comments to evaluate.

@risu729 risu729 marked this pull request as ready for review May 8, 2026 13:35
@jdx jdx merged commit 709eee5 into jdx:main May 10, 2026
34 checks passed
@risu729 risu729 deleted the fix/bash-chpwd-nounset branch May 10, 2026 13:31
mise-en-dev added a commit that referenced this pull request May 11, 2026
### πŸš€ Features

- **(cli)** add minimum release age flag to lock and ls-remote by
@risu729 in [#9269](#9269)
- **(config)** add run field for hooks by @risu729 in
[#9718](#9718)
- **(github)** add native oauth token source by @jdx in
[#9654](#9654)
- **(oci)** scope build to project config by default by @jdx in
[#9766](#9766)
- add support for prefixed latest version queries in outdated checks by
@roele in [#9767](#9767)

### πŸ› Bug Fixes

- **(activate)** guard bash chpwd hook under nounset by @risu729 in
[#9716](#9716)
- **(backend)** date-check latest stable fast path by @risu729 in
[#9650](#9650)
- **(config)** parse core tool options consistently by @risu729 in
[#9742](#9742)
- **(exec)** propagate __MISE_DIFF so nested mise recovers pristine PATH
by @jdx in [#9765](#9765)
- **(forgejo)** include prereleases when opted in by @risu729 in
[#9717](#9717)
- **(github)** avoid caching empty release assets by @risu729 in
[#9616](#9616)
- **(java)** resolve lockfile URLs from metadata by @risu729 in
[#9719](#9719)
- **(lock)** cache unavailable github attestations by @risu729 in
[#9741](#9741)
- **(pipx)** preserve options when reinstalling tools by @risu729 in
[#9663](#9663)
- **(python)** skip redundant lockfile provenance verification by
@risu729 in [#9739](#9739)
- **(vfox)** run pre_uninstall hook by @risu729 in
[#9662](#9662)

### 🚜 Refactor

- **(schema)** extract tool options definition by @risu729 in
[#9649](#9649)

### ⚑ Performance

- **(aqua)** bake rkyv aqua package blobs by @risu729 in
[#9535](#9535)

### πŸ“¦οΈ Dependency Updates

- lock file maintenance by @renovate[bot] in
[#9773](#9773)

### πŸ“¦ Registry

- add vector
([github:vectordotdev/vector](https://github.com/vectordotdev/vector))
by @kquinsland in [#9761](#9761)
- add oc and openshift-install (http backend) by @konono in
[#9669](#9669)

### New Contributors

- @konono made their first contribution in
[#9669](#9669)
- @kquinsland made their first contribution in
[#9761](#9761)
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.

2 participants