[Fix] Reject bare LTS codenames in nvm install

Previously, `nvm install Argon` would succeed by matching the LTS name
in the version description (e.g., "v4.9.1 (Latest LTS: Argon)"), but
`nvm uninstall Argon` would fail because "Argon" is not a valid alias or not a valid version.

Changes:
- Added pattern matching check in nvm_remote_version (nvm.sh:785-791)
- Skips check for implicit aliases (node, stable, etc.) to preserve
  existing functionality
- Added unit tests to verify LTS names are rejected while version
  numbers still work
After this fix:
- `nvm install Argon` → fails (use `nvm install lts/argon` instead)
- `nvm install 4` → still works
- `nvm install node` → still works
- `nvm install lts/argon` → still works

This makes install and uninstall behavior consistent.

Fixes #3474.
This commit is contained in:
Rahul Beniwal
2025-11-24 21:57:39 +05:30
committed by Jordan Harband
parent 26066c10f4
commit 81f13638d7
2 changed files with 29 additions and 0 deletions

View File

@@ -75,4 +75,24 @@ EXIT_CODE="$(nvm_remote_version node >/dev/null 2>&1 ; echo $?)"
|| die "nvm_remote_version node did not return contents of nvm_ls_remote node; got $OUTPUT"
[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version node did not exit with 0, got $EXIT_CODE"
# Test LTS name rejection (Issue #3474)
# When nvm_remote_versions returns a line with LTS name in description,
# nvm_remote_version should reject it if the pattern doesn't match the version number
nvm_remote_versions() {
echo "v4.9.1 Argon *"
}
OUTPUT="$(nvm_remote_version Argon)"
EXIT_CODE="$(nvm_remote_version Argon >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_N/A" ] || die "nvm_remote_version Argon should return N/A (LTS name not in version), got $OUTPUT"
[ "_$EXIT_CODE" = "_3" ] || die "nvm_remote_version Argon should exit with code 3, got $EXIT_CODE"
nvm_remote_versions() {
echo "v4.9.1"
}
OUTPUT="$(nvm_remote_version 4)"
EXIT_CODE="$(nvm_remote_version 4 >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_v4.9.1" ] || die "nvm_remote_version 4 should return v4.9.1, got $OUTPUT"
[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version 4 should exit with code 0, got $EXIT_CODE"
cleanup