Skip to content

Commit 5385541

Browse files
committed
[Fix] avoid an unbound variable
Fixes nvm-sh#3820
1 parent 1f70aea commit 5385541

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

nvm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4328,7 +4328,7 @@ nvm() {
43284328

43294329
local NVM_OUTPUT
43304330
local EXIT_CODE
4331-
NVM_OUTPUT="$(NVM_LTS="${NVM_LTS-}" nvm_remote_versions "${PATTERN}" &&:)"
4331+
NVM_OUTPUT="$(NVM_LTS="${NVM_LTS-}" nvm_remote_versions "${PATTERN-}" &&:)"
43324332
EXIT_CODE=$?
43334333
if [ -n "${NVM_OUTPUT}" ]; then
43344334
NVM_NO_COLORS="${NVM_NO_COLORS-}" nvm_print_versions "${NVM_OUTPUT}"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
die () { echo "$@" ; cleanup ; exit 1; }
4+
5+
cleanup() {
6+
unset -f nvm_download nvm_ls_remote nvm_ls_remote_iojs
7+
}
8+
9+
: nvm.sh
10+
\. ../../../nvm.sh
11+
12+
\. ../../common.sh
13+
14+
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
15+
nvm_ls_remote() {
16+
cat "${REMOTE}"
17+
}
18+
REMOTE_IOJS="${PWD}/mocks/nvm_ls_remote_iojs.txt"
19+
nvm_ls_remote_iojs() {
20+
cat "${REMOTE_IOJS}"
21+
}
22+
23+
# Enable no unset variable; regression test for https://github.com/nvm-sh/nvm/issues/3820
24+
set -u
25+
26+
# Bare `nvm ls-remote` (no pattern argument) must not error on unset PATTERN
27+
output=$(nvm ls-remote 2>&1 1>/dev/null) || die "nvm ls-remote with nounset failed: ${output}"
28+
test -z "${output}" || die "expected empty stderr; got >${output}<"
29+
30+
cleanup

0 commit comments

Comments
 (0)