Skip to content

Commit

Permalink
[Fix] nvm_download: ensure all args are quoted
Browse files Browse the repository at this point in the history
Fixes #3411.
  • Loading branch information
ljharb committed Aug 21, 2024
1 parent 863bd63 commit 0ce8f5a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ nvm_download() {
if nvm_curl_use_compression; then
CURL_COMPRESSED_FLAG="--compressed"
fi
eval "curl -q --fail ${CURL_COMPRESSED_FLAG:-} ${CURL_HEADER_FLAG:-} $*"
local NVM_DOWNLOAD_ARGS
NVM_DOWNLOAD_ARGS=''
for arg in "$@"; do
NVM_DOWNLOAD_ARGS="${NVM_DOWNLOAD_ARGS} \"$arg\""
done
eval "curl -q --fail ${CURL_COMPRESSED_FLAG:-} ${CURL_HEADER_FLAG:-} ${NVM_DOWNLOAD_ARGS}"
elif nvm_has "wget"; then
# Emulate curl with wget
ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \
Expand Down
3 changes: 3 additions & 0 deletions test/fast/Unit tests/nvm_download
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ NVM_AUTH_HEADER="Bearer test-token" nvm_download "http://127.0.0.1/bearer" > /de
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'
docker stop httpbin && docker rm httpbin

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

cleanup
2 changes: 1 addition & 1 deletion test/install_script/nvm_download
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" >/de

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

cleanup

0 comments on commit 0ce8f5a

Please sign in to comment.