`nvm alias`: explicitly forbid user aliases in subdirs.
parent
1eb4d482e0
commit
677c69dda0
8
nvm.sh
8
nvm.sh
|
@ -2318,6 +2318,10 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d'
|
||||||
nvm unalias "${2-}"
|
nvm unalias "${2-}"
|
||||||
return $?
|
return $?
|
||||||
fi
|
fi
|
||||||
|
if [ "${2#*\/}" != "${2-}" ]; then
|
||||||
|
>&2 echo "Aliases in subdirectories are not supported."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
VERSION="$(nvm_version "${3-}")"
|
VERSION="$(nvm_version "${3-}")"
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "! WARNING: Version '${3-}' does not exist." >&2
|
echo "! WARNING: Version '${3-}' does not exist." >&2
|
||||||
|
@ -2337,6 +2341,10 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d'
|
||||||
>&2 nvm help
|
>&2 nvm help
|
||||||
return 127
|
return 127
|
||||||
fi
|
fi
|
||||||
|
if [ "${2#*\/}" != "${2-}" ]; then
|
||||||
|
>&2 echo "Aliases in subdirectories are not supported."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
[ ! -f "$NVM_ALIAS_DIR/$2" ] && echo "Alias $2 doesn't exist!" >&2 && return
|
[ ! -f "$NVM_ALIAS_DIR/$2" ] && echo "Alias $2 doesn't exist!" >&2 && return
|
||||||
local NVM_ALIAS_ORIGINAL
|
local NVM_ALIAS_ORIGINAL
|
||||||
NVM_ALIAS_ORIGINAL="$(nvm_alias "$2")"
|
NVM_ALIAS_ORIGINAL="$(nvm_alias "$2")"
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. ../../../nvm.sh
|
||||||
|
|
||||||
|
die () { echo $@ ; exit 1; }
|
||||||
|
|
||||||
|
OUTPUT="$(nvm alias foo/bar baz 2>&1)"
|
||||||
|
EXPECTED_OUTPUT="Aliases in subdirectories are not supported."
|
||||||
|
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to create an alias with a slash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
|
||||||
|
|
||||||
|
EXIT_CODE="$(nvm alias foo/bar baz >/dev/null 2>&1 ; echo $?)"
|
||||||
|
[ "$EXIT_CODE" = "1" ] || die "trying to create an alias with a slash should fail with code 1, got '$EXIT_CODE'"
|
||||||
|
|
||||||
|
OUTPUT="$(nvm alias foo/ baz 2>&1)"
|
||||||
|
EXPECTED_OUTPUT="Aliases in subdirectories are not supported."
|
||||||
|
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to create an alias ending with a slash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
|
||||||
|
|
||||||
|
EXIT_CODE="$(nvm alias foo/ baz >/dev/null 2>&1 ; echo $?)"
|
||||||
|
[ "$EXIT_CODE" = "1" ] || die "trying to create an alias ending with a slash should fail with code 1, got '$EXIT_CODE'"
|
||||||
|
|
||||||
|
OUTPUT="$(nvm alias /bar baz 2>&1)"
|
||||||
|
EXPECTED_OUTPUT="Aliases in subdirectories are not supported."
|
||||||
|
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to create an alias starting with a slash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
|
||||||
|
|
||||||
|
EXIT_CODE="$(nvm alias /bar baz >/dev/null 2>&1 ; echo $?)"
|
||||||
|
[ "$EXIT_CODE" = "1" ] || die "trying to create an alias starting with a slash should fail with code 1, got '$EXIT_CODE'"
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
. ../../../nvm.sh
|
||||||
|
|
||||||
|
die () { echo $@ ; exit 1; }
|
||||||
|
|
||||||
|
OUTPUT="$(nvm unalias foo/bar 2>&1)"
|
||||||
|
EXPECTED_OUTPUT="Aliases in subdirectories are not supported."
|
||||||
|
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove an alias with a slash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
|
||||||
|
|
||||||
|
EXIT_CODE="$(nvm unalias foo/bar >/dev/null 2>&1 ; echo $?)"
|
||||||
|
[ "$EXIT_CODE" = "1" ] || die "trying to remove an alias with a slash should fail with code 1, got '$EXIT_CODE'"
|
||||||
|
|
||||||
|
OUTPUT="$(nvm unalias foo/ 2>&1)"
|
||||||
|
EXPECTED_OUTPUT="Aliases in subdirectories are not supported."
|
||||||
|
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove an alias ending with a slash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
|
||||||
|
|
||||||
|
EXIT_CODE="$(nvm unalias foo/ >/dev/null 2>&1 ; echo $?)"
|
||||||
|
[ "$EXIT_CODE" = "1" ] || die "trying to remove an alias ending with a slash should fail with code 1, got '$EXIT_CODE'"
|
||||||
|
|
||||||
|
OUTPUT="$(nvm unalias /bar 2>&1)"
|
||||||
|
EXPECTED_OUTPUT="Aliases in subdirectories are not supported."
|
||||||
|
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove an alias starting with a slash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
|
||||||
|
|
||||||
|
EXIT_CODE="$(nvm unalias /bar >/dev/null 2>&1 ; echo $?)"
|
||||||
|
[ "$EXIT_CODE" = "1" ] || die "trying to remove an alias starting with a slash should fail with code 1, got '$EXIT_CODE'"
|
||||||
|
|
Loading…
Reference in New Issue