From d200a215594bdda07e130117c9d392fff29cba84 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 26 Mar 2026 10:18:40 -0700 Subject: [PATCH] [Fix] `nvm_normalize_lts`: only reject uppercase for LTS names, not regular aliases The lowercase check was in the `*` catch-all branch of the `case` statement, rejecting any alias name with uppercase characters. This prevented creating or reading uppercase aliases like `TESTY`. The check should only apply to `lts/*` patterns, since LTS codenames are always lowercase. Fixes #3764. Bug introduced in https://github.com/nvm-sh/nvm/commit/9fb9dec710e2c8d3aecb24c2a7c9f9fb45b1435b as part of fixing #3417. --- nvm.sh | 12 ++++-- .../Aliases/uppercase alias names should work | 37 +++++++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) create mode 100755 test/fast/Aliases/uppercase alias names should work diff --git a/nvm.sh b/nvm.sh index 7268de2..b2f45ea 100755 --- a/nvm.sh +++ b/nvm.sh @@ -935,10 +935,14 @@ nvm_normalize_lts() { fi ;; *) - if [ "${LTS}" != "$(echo "${LTS}" | command tr '[:upper:]' '[:lower:]')" ]; then - nvm_err 'LTS names must be lowercase' - return 3 - fi + case "${LTS}" in + lts/*) + if [ "${LTS}" != "$(echo "${LTS}" | command tr '[:upper:]' '[:lower:]')" ]; then + nvm_err 'LTS names must be lowercase' + return 3 + fi + ;; + esac nvm_echo "${LTS}" ;; esac diff --git a/test/fast/Aliases/uppercase alias names should work b/test/fast/Aliases/uppercase alias names should work new file mode 100755 index 0000000..ed38974 --- /dev/null +++ b/test/fast/Aliases/uppercase alias names should work @@ -0,0 +1,37 @@ +#!/bin/sh + +die () { echo "$@" ; cleanup ; exit 1; } + +cleanup() { + rm -f "$(nvm_alias_path)/UPPER_ALIAS" + rm -f "$(nvm_alias_path)/MixedCase" +} + +: nvm.sh +\. ../../../nvm.sh + +\. ../../common.sh + +make_fake_node v0.0.1 + +# Uppercase alias should be created and readable +nvm alias UPPER_ALIAS v0.0.1 +[ -f "$(nvm_alias_path)/UPPER_ALIAS" ] || die "uppercase alias file should exist" + +try nvm_alias UPPER_ALIAS +[ "${CAPTURED_EXIT_CODE}" = "0" ] || die "nvm_alias should succeed for uppercase alias, got exit code ${CAPTURED_EXIT_CODE}" +[ "${CAPTURED_STDOUT}" = "v0.0.1" ] || die "nvm_alias UPPER_ALIAS should return v0.0.1, got ${CAPTURED_STDOUT}" + +# Mixed case should also work +nvm alias MixedCase v0.0.1 +[ -f "$(nvm_alias_path)/MixedCase" ] || die "mixed case alias file should exist" + +try nvm_alias MixedCase +[ "${CAPTURED_EXIT_CODE}" = "0" ] || die "nvm_alias should succeed for mixed case alias, got exit code ${CAPTURED_EXIT_CODE}" + +# LTS names with uppercase should still be rejected +try_err nvm_normalize_lts "lts/ARGON" +[ "${CAPTURED_EXIT_CODE}" = "3" ] || die "uppercase LTS name should fail with exit code 3, got ${CAPTURED_EXIT_CODE}" +[ "${CAPTURED_STDERR}" = "LTS names must be lowercase" ] || die "expected lowercase error, got ${CAPTURED_STDERR}" + +cleanup