1
0
mirror of https://github.com/nvm-sh/nvm.git synced 2026-10-24 23:33:43 +08:00

[Fix] avoid an unbound variable

Fixes #3820
This commit is contained in:
Jordan Harband
2026-05-15 23:08:37 -07:00
parent 1f70aea0b0
commit 53855417eb
2 changed files with 31 additions and 1 deletions

2
nvm.sh
View File

@@ -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}"

View File

@@ -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