Skip to content

Commit 0ce8f5a

Browse files
committed
[Fix] nvm_download: ensure all args are quoted
Fixes #3411.
1 parent 863bd63 commit 0ce8f5a

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

nvm.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ nvm_download() {
128128
if nvm_curl_use_compression; then
129129
CURL_COMPRESSED_FLAG="--compressed"
130130
fi
131-
eval "curl -q --fail ${CURL_COMPRESSED_FLAG:-} ${CURL_HEADER_FLAG:-} $*"
131+
local NVM_DOWNLOAD_ARGS
132+
NVM_DOWNLOAD_ARGS=''
133+
for arg in "$@"; do
134+
NVM_DOWNLOAD_ARGS="${NVM_DOWNLOAD_ARGS} \"$arg\""
135+
done
136+
eval "curl -q --fail ${CURL_COMPRESSED_FLAG:-} ${CURL_HEADER_FLAG:-} ${NVM_DOWNLOAD_ARGS}"
132137
elif nvm_has "wget"; then
133138
# Emulate curl with wget
134139
ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \

test/fast/Unit tests/nvm_download

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ NVM_AUTH_HEADER="Bearer test-token" nvm_download "http://127.0.0.1/bearer" > /de
2525
nvm_download "http://127.0.0.1/bearer" > /dev/null && die 'nvm_download with no auth header should not send the header and should fail'
2626
docker stop httpbin && docker rm httpbin
2727

28+
# ensure quoted extra args remain quoted
29+
nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" -o "; die quoted-command-not-quoted" || die 'command failed'
30+
2831
cleanup

test/install_script/nvm_download

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" >/de
1212

1313
# nvm_download should fail to download wrong_install.sh
1414
if nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/wrong_install.sh" &>/dev/null; then
15-
die "nvm_download should fail to download no existing file"
15+
die "nvm_download should fail to download nonexistent file"
1616
fi
1717

1818
cleanup

0 commit comments

Comments
 (0)