mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-04-11 14:11:41 +08:00
[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 9fb9dec710 as part of fixing #3417.
This commit is contained in:
parent
001ea8cac1
commit
d200a21559
12
nvm.sh
12
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
|
||||
|
||||
37
test/fast/Aliases/uppercase alias names should work
Executable file
37
test/fast/Aliases/uppercase alias names should work
Executable file
@ -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
|
||||
Loading…
Reference in New Issue
Block a user