diff --git a/nvm.sh b/nvm.sh index 0ca5fd7..1a98f3c 100644 --- a/nvm.sh +++ b/nvm.sh @@ -257,6 +257,11 @@ if [ -z "${NVM_DIR-}" ]; then # shellcheck disable=SC1001 NVM_DIR="$(nvm_cd ${NVM_CD_FLAGS} "$(dirname "${NVM_SCRIPT_SOURCE:-$0}")" > /dev/null && \pwd)" export NVM_DIR +else + while echo "${NVM_DIR}" | nvm_grep -q "/$"; do + export NVM_DIR="${NVM_DIR%/}" + done + nvm_err "Warning: \$NVM_DIR should not have trailing slash" fi unset NVM_SCRIPT_SOURCE 2> /dev/null diff --git a/test/fast/nvm should remove the last trailing slash in $NVM_DIR b/test/fast/nvm should remove the last trailing slash in $NVM_DIR new file mode 100644 index 0000000..4babb54 --- /dev/null +++ b/test/fast/nvm should remove the last trailing slash in $NVM_DIR @@ -0,0 +1,18 @@ +#!/bin/sh + +set -ex + +die () { echo "$@" ; exit 1; } + +export NVM_DIR_BASE="/tmp" +export NVM_DIR="${NVM_DIR_BASE}/" + +\. ../../nvm.sh + +[ "${NVM_DIR}" = "${NVM_DIR_BASE}" ] || die 'nvm should remove the last trailing slash in "$NVM_DIR"' + +export NVM_DIR="${NVM_DIR_BASE}//" + +\. ../../nvm.sh + +[ "${NVM_DIR}" = "${NVM_DIR_BASE}" ] || die 'nvm should remove all the last trailing slashes in "$NVM_DIR"'