[Fix] nvm_remote_version: match the requested version as a whole version component
The check that the resolved version actually matches the request used an unanchored substring match on the raw pattern, so `nvm install 20` could accept `v10.20.0` when a remote list's row was selected by a `v20` in its LTS column and no 20.x rows were present. Match the `v`-prefixed pattern followed by a non-digit against the version instead, the same way `nvm_ls_remote_index_tab` normalizes it, so `20` no longer matches `v10.20.0` or `v200.0.0`, while regex-style requests like `4.*` and `v[68]`, and a trailing dot like `8.`, keep working. This also fixes `iojs-1` and `iojs-3`, which previously resolved to N/A because `iojs-3` is not a substring of `iojs-v3.3.1`. Discovered by Anthropic's OSS Scanner, as bug ANT-2026-7GFFYVJP; the scanner correctly classified it as not a vulnerability.
This commit is contained in:
2 files changed
+57
-1
No files matched your search
@@ -1023,7 +1023,8 @@ nvm_remote_version() {
|
||||
if [ -n "${PATTERN}" ] && [ "_${VERSION}" != "_N/A" ] && ! nvm_validate_implicit_alias "${PATTERN}" 2>/dev/null; then
|
||||
local VERSION_NUM
|
||||
VERSION_NUM="$(nvm_echo "${VERSION}" | command awk '{print $1}')"
|
||||
if ! nvm_echo "${VERSION_NUM}" | nvm_grep -q "${PATTERN}"; then
|
||||
# the `v` prefix and the trailing non-digit keep `20` from matching `v10.20.0` or `v200.0.0`
|
||||
if ! nvm_echo "${VERSION_NUM} " | nvm_grep -q "$(nvm_ensure_version_prefix "${PATTERN%.}")[^0-9]"; then
|
||||
VERSION='N/A'
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user