[Fix] nvm: do not change or export the caller's IFS

`IFS=... nvm "$@"` is a prefix assignment to a function call, which bash's POSIX mode (macOS `/bin/sh`) keeps after the call returns, and exports.
This commit is contained in:
Jordan Harband
2026-09-30 15:50:38 +09:00
parent 3bfc2b4a9a
commit 0add6b8555
2 changed files with 31 additions and 4 deletions
+12 -4
View File
@@ -3672,14 +3672,18 @@ nvm() {
if [ "${-#*e}" != "$-" ]; then if [ "${-#*e}" != "$-" ]; then
set +e set +e
local EXIT_CODE local EXIT_CODE
IFS="${DEFAULT_IFS}" nvm "$@" local IFS
IFS="${DEFAULT_IFS}"
nvm "$@"
EXIT_CODE="$?" EXIT_CODE="$?"
set -e set -e
return "$EXIT_CODE" return "$EXIT_CODE"
elif [ "${-#*a}" != "$-" ]; then elif [ "${-#*a}" != "$-" ]; then
set +a set +a
local EXIT_CODE local EXIT_CODE
IFS="${DEFAULT_IFS}" nvm "$@" local IFS
IFS="${DEFAULT_IFS}"
nvm "$@"
EXIT_CODE="$?" EXIT_CODE="$?"
set -a set -a
return "$EXIT_CODE" return "$EXIT_CODE"
@@ -3687,13 +3691,17 @@ nvm() {
# shellcheck disable=SC3041 # shellcheck disable=SC3041
set +E set +E
local EXIT_CODE local EXIT_CODE
IFS="${DEFAULT_IFS}" nvm "$@" local IFS
IFS="${DEFAULT_IFS}"
nvm "$@"
EXIT_CODE="$?" EXIT_CODE="$?"
# shellcheck disable=SC3041 # shellcheck disable=SC3041
set -E set -E
return "$EXIT_CODE" return "$EXIT_CODE"
elif [ "${IFS}" != "${DEFAULT_IFS}" ]; then elif [ "${IFS}" != "${DEFAULT_IFS}" ]; then
IFS="${DEFAULT_IFS}" nvm "$@" local IFS
IFS="${DEFAULT_IFS}"
nvm "$@"
return "$?" return "$?"
fi fi
@@ -0,0 +1,19 @@
#!/bin/sh
die () { IFS=' '; echo "$@" ; exit 1; }
: nvm.sh
\. ../../nvm.sh
IFS=':'
nvm --version >/dev/null
[ "${IFS}" = ':' ] || die "nvm changed the caller's IFS; got >${IFS}<"
set -e
nvm --version >/dev/null
set +e
[ "${IFS}" = ':' ] || die "nvm changed the caller's IFS under set -e; got >${IFS}<"
! env | grep -q '^IFS=' || die 'nvm exported IFS'
IFS=' '