diff --git a/nvm.sh b/nvm.sh index 4ba5568..295703c 100755 --- a/nvm.sh +++ b/nvm.sh @@ -4328,7 +4328,7 @@ nvm() { local NVM_OUTPUT local EXIT_CODE - NVM_OUTPUT="$(NVM_LTS="${NVM_LTS-}" nvm_remote_versions "${PATTERN}" &&:)" + NVM_OUTPUT="$(NVM_LTS="${NVM_LTS-}" nvm_remote_versions "${PATTERN-}" &&:)" EXIT_CODE=$? if [ -n "${NVM_OUTPUT}" ]; then NVM_NO_COLORS="${NVM_NO_COLORS-}" nvm_print_versions "${NVM_OUTPUT}" diff --git a/test/fast/Unit tests/nvm ls-remote with nounset should not fail b/test/fast/Unit tests/nvm ls-remote with nounset should not fail new file mode 100755 index 0000000..89d1eaa --- /dev/null +++ b/test/fast/Unit tests/nvm ls-remote with nounset should not fail @@ -0,0 +1,30 @@ +#!/bin/sh + +die () { echo "$@" ; cleanup ; exit 1; } + +cleanup() { + unset -f nvm_download nvm_ls_remote nvm_ls_remote_iojs +} + +: nvm.sh +\. ../../../nvm.sh + +\. ../../common.sh + +REMOTE="${PWD}/mocks/nvm_ls_remote.txt" +nvm_ls_remote() { + cat "${REMOTE}" +} +REMOTE_IOJS="${PWD}/mocks/nvm_ls_remote_iojs.txt" +nvm_ls_remote_iojs() { + cat "${REMOTE_IOJS}" +} + +# Enable no unset variable; regression test for https://github.com/nvm-sh/nvm/issues/3820 +set -u + +# Bare `nvm ls-remote` (no pattern argument) must not error on unset PATTERN +output=$(nvm ls-remote 2>&1 1>/dev/null) || die "nvm ls-remote with nounset failed: ${output}" +test -z "${output}" || die "expected empty stderr; got >${output}<" + +cleanup