[Fix] nvm_ls_remote, nvm_remote_version: match dots between version components literally

The version pattern went to grep with its dots unescaped,
so each one matched any character:
`20.1` also matched `v2041.0.0`,
and `20.1.1` matched `v20.111.1`,
so `nvm_remote_version 20.1.1` resolved to `v20.111.1`.

Escape each dot that is followed by a digit,
keeping any other regex syntax in the pattern, like `v[68]`.
This commit is contained in:
Soujas K authored and Jordan Harband committed 2026-11-04 13:32:35 +05:30
1 parent 699c898671
commit ed2de88826
2 files changed
+56 -3

No files matched your search

@@ -0,0 +1,45 @@
#!/bin/sh
die () { echo "$@" ; cleanup ; exit 1; }
cleanup() {
unset -f nvm_download nvm_record_lts_status
}
: nvm.sh
\. ../../../nvm.sh
# these mocks must not be recorded as the LTS status of $NVM_DIR's versions
nvm_record_lts_status() { :; }
nvm_download() {
command printf '%s\n' \
'version date files npm v8 uv zlib openssl modules lts security' \
'v2041.0.0 2026-01-01 linux-x64 10.0.0 1 1 1 1 115 - -' \
'v20.111.1 2026-01-01 linux-x64 10.0.0 1 1 1 1 115 - -' \
'v20.10.0 2026-01-01 linux-x64 10.0.0 1 1 1 1 115 - -' \
'v20.1.1 2026-01-01 linux-x64 10.0.0 1 1 1 1 115 - -' \
'v20.1.0 2026-01-01 linux-x64 10.0.0 1 1 1 1 115 - -'
}
\. ../../common.sh
# Dots in the pattern are literal, so they must not match other digits.
OUTPUT="$(nvm_ls_remote 20.1)"
EXPECTED_OUTPUT='v20.1.0
v20.1.1'
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm_ls_remote 20.1: expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"
OUTPUT="$(nvm_ls_remote 20.1.1)"
[ "_${OUTPUT}" = '_v20.1.1' ] || die "nvm_ls_remote 20.1.1: expected >v20.1.1<, got >${OUTPUT}<"
try nvm_ls_remote 20.1.2
[ "_${CAPTURED_STDOUT}" = '_N/A' ] || die "nvm_ls_remote 20.1.2: expected >N/A<, got >${CAPTURED_STDOUT}<"
OUTPUT="$(nvm_remote_version 20.1.1)"
[ "_${OUTPUT}" = '_v20.1.1' ] || die "nvm_remote_version 20.1.1: expected >v20.1.1<, got >${OUTPUT}<"
try nvm_remote_version 20.1.2
[ "_${CAPTURED_STDOUT}" = '_N/A' ] || die "nvm_remote_version 20.1.2: expected >N/A<, got >${CAPTURED_STDOUT}<"
cleanup