Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

`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.

authored by Jordan Harband · committed by Jordan Harband · parent 3bfc2b4 · Browse files · 2 files+31 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+31 added−4 removed

  • tests:+19 added−0 removed
  • other:+12 added−4 removed

2 files+31 added−4 removed

added:test/fast/Running 'nvm' should not change or export the caller's IFS+19 added
1#!/bin/sh23die () { IFS=' '; echo "$@" ; exit 1; }45: nvm.sh6\. ../../nvm.sh78IFS=':'9nvm --version >/dev/null10[ "${IFS}" = ':' ] || die "nvm changed the caller's IFS; got >${IFS}<"1112set -e13nvm --version >/dev/null14set +e15[ "${IFS}" = ':' ] || die "nvm changed the caller's IFS under set -e; got >${IFS}<"1617! env | grep -q '^IFS=' || die 'nvm exported IFS'1819IFS=' '
modified:nvm.sh+12 added-4 removed
3670 unmodified lines
3671"3672 if [ "${-#*e}" != "$-" ]; then3673 set +e3674 local EXIT_CODE3675 local IFS3675 IFS="${DEFAULT_IFS}" nvm "$@"3676 IFS="${DEFAULT_IFS}"3677 nvm "$@"3678 EXIT_CODE="$?"3679 set -e3680 return "$EXIT_CODE"3681 elif [ "${-#*a}" != "$-" ]; then3682 set +a3683 local EXIT_CODE3684 local IFS3682 IFS="${DEFAULT_IFS}" nvm "$@"3685 IFS="${DEFAULT_IFS}"3686 nvm "$@"3687 EXIT_CODE="$?"3688 set -a3689 return "$EXIT_CODE"3690 elif [ -n "${BASH-}" ] && [ "${-#*E}" != "$-" ]; then3691 # shellcheck disable=SC30413692 set +E3693 local EXIT_CODE3694 local IFS3690 IFS="${DEFAULT_IFS}" nvm "$@"3695 IFS="${DEFAULT_IFS}"3696 nvm "$@"3697 EXIT_CODE="$?"3698 # shellcheck disable=SC30413699 set -E3700 return "$EXIT_CODE"3701 elif [ "${IFS}" != "${DEFAULT_IFS}" ]; then3702 local IFS3696 IFS="${DEFAULT_IFS}" nvm "$@"3703 IFS="${DEFAULT_IFS}"3704 nvm "$@"3705 return "$?"3706 fi37073708 local i
1724 unmodified lines