Skip to content

Commit

Permalink
[Fix] Remove $NVM_DIR trailing slash automatically, fix nvm-sh#1708
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterDaveHello committed Apr 24, 2018
1 parent d5dacdf commit 30bc836
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,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

Expand Down
18 changes: 18 additions & 0 deletions test/fast/nvm should remove the last trailing slash in $NVM_DIR
Original file line number Diff line number Diff line change
@@ -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"'

0 comments on commit 30bc836

Please sign in to comment.