Skip to content
Myr

[Fix] Reject bare LTS codenames in nvm install

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Rahul Beniwal · committed by Jordan Harband · parent 26066c1 · Browse files · 2 files+29 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+29 added−0 removed

  • tests:+20 added−0 removed
  • other:+9 added−0 removed

2 files+29 added−0 removed

modified:test/fast/Unit tests/nvm_remote_version+20 added
73 unmodified lines
74[ "_$OUTPUT" = "_$(nvm_ls_remote node)" ] \75 || die "nvm_remote_version node did not return contents of nvm_ls_remote node; got $OUTPUT"76[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version node did not exit with 0, got $EXIT_CODE"7778# Test LTS name rejection (Issue #3474)79# When nvm_remote_versions returns a line with LTS name in description,80# nvm_remote_version should reject it if the pattern doesn't match the version number8182nvm_remote_versions() {83 echo "v4.9.1 Argon *"84}85OUTPUT="$(nvm_remote_version Argon)"86EXIT_CODE="$(nvm_remote_version Argon >/dev/null 2>&1 ; echo $?)"87[ "_$OUTPUT" = "_N/A" ] || die "nvm_remote_version Argon should return N/A (LTS name not in version), got $OUTPUT"88[ "_$EXIT_CODE" = "_3" ] || die "nvm_remote_version Argon should exit with code 3, got $EXIT_CODE"8990nvm_remote_versions() {91 echo "v4.9.1"92}93OUTPUT="$(nvm_remote_version 4)"94EXIT_CODE="$(nvm_remote_version 4 >/dev/null 2>&1 ; echo $?)"95[ "_$OUTPUT" = "_v4.9.1" ] || die "nvm_remote_version 4 should return v4.9.1, got $OUTPUT"96[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version 4 should exit with code 0, got $EXIT_CODE"9798cleanup
modified:nvm.sh+9 added
779 unmodified lines
780 esac781 else782 VERSION="$(NVM_LTS="${NVM_LTS-}" nvm_remote_versions "${PATTERN}" | command tail -1)"783 fi784785 if [ -n "${PATTERN}" ] && [ "_${VERSION}" != "_N/A" ] && ! nvm_validate_implicit_alias "${PATTERN}" 2>/dev/null; then786 local VERSION_NUM787 VERSION_NUM="$(nvm_echo "${VERSION}" | command awk '{print $1}')"788 if ! nvm_echo "${VERSION_NUM}" | nvm_grep -q "${PATTERN}"; then789 VERSION='N/A'790 fi791 fi792793 if [ -n "${NVM_VERSION_ONLY-}" ]; then794 command awk 'BEGIN {795 n = split(ARGV[1], a);796 print a[1]
3875 unmodified lines