diff --git a/nvm.sh b/nvm.sh index 5581998..f2744c6 100644 --- a/nvm.sh +++ b/nvm.sh @@ -3335,6 +3335,18 @@ nvm() { nvm_err 'Aliases in subdirectories are not supported.' return 1 fi + + local NVM_IOJS_PREFIX + local NVM_NODE_PREFIX + NVM_IOJS_PREFIX="$(nvm_iojs_prefix)" + NVM_NODE_PREFIX="$(nvm_node_prefix)" + case "$1" in + "stable" | "unstable" | "${NVM_IOJS_PREFIX}" | "${NVM_NODE_PREFIX}" | "system") + nvm_err "${1-} is a default (built-in) alias and cannot be deleted." + return 1 + ;; + esac + [ ! -f "${NVM_ALIAS_DIR}/${1-}" ] && nvm_err "Alias ${1-} doesn't exist!" && return local NVM_ALIAS_ORIGINAL NVM_ALIAS_ORIGINAL="$(nvm_alias "${1}")" diff --git "a/test/fast/Aliases/\"nvm unalias\" should not accept aliases with names equal to built-in alias" "b/test/fast/Aliases/\"nvm unalias\" should not accept aliases with names equal to built-in alias" new file mode 100755 index 0000000..35bdc8f --- /dev/null +++ "b/test/fast/Aliases/\"nvm unalias\" should not accept aliases with names equal to built-in alias" @@ -0,0 +1,25 @@ +#!/bin/sh + +\. ../../../nvm.sh + +die () { echo "$@" ; exit 1; } + +OUTPUT="$(nvm unalias node 2>&1)" +EXPECTED_OUTPUT="node is a default (built-in) alias and cannot be deleted." +[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'" + +OUTPUT="$(nvm unalias stable 2>&1)" +EXPECTED_OUTPUT="stable is a default (built-in) alias and cannot be deleted." +[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'" + +OUTPUT="$(nvm unalias unstable 2>&1)" +EXPECTED_OUTPUT="unstable is a default (built-in) alias and cannot be deleted." +[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'" + +OUTPUT="$(nvm unalias iojs 2>&1)" +EXPECTED_OUTPUT="iojs is a default (built-in) alias and cannot be deleted." +[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'" + +OUTPUT="$(nvm unalias system 2>&1)" +EXPECTED_OUTPUT="system is a default (built-in) alias and cannot be deleted." +[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"