diff --git a/nvm.sh b/nvm.sh index 297f5ff..87f4961 100644 --- a/nvm.sh +++ b/nvm.sh @@ -698,13 +698,12 @@ nvm_strip_path() { nvm_err '${NVM_DIR} not set!' return 1 fi - nvm_echo "${1-}" | command sed \ - -e "s#${NVM_DIR}/[^/]*${2-}[^:]*:##g" \ - -e "s#:${NVM_DIR}/[^/]*${2-}[^:]*##g" \ - -e "s#${NVM_DIR}/[^/]*${2-}[^:]*##g" \ - -e "s#${NVM_DIR}/versions/[^/]*/[^/]*${2-}[^:]*:##g" \ - -e "s#:${NVM_DIR}/versions/[^/]*/[^/]*${2-}[^:]*##g" \ - -e "s#${NVM_DIR}/versions/[^/]*/[^/]*${2-}[^:]*##g" + command printf %s "${1-}" | command awk -v NVM_DIR="${NVM_DIR}" -v RS=: ' + index($0, NVM_DIR) == 1 { + path = substr($0, length(NVM_DIR) + 1) + if (path ~ "^(/versions/[^/]*)?/[^/]*'"${2-}"'.*$") { next } + } + { print }' | command paste -s -d: - } nvm_change_path() { diff --git a/test/fast/Unit tests/nvm_strip_path b/test/fast/Unit tests/nvm_strip_path index a57a424..adce734 100755 --- a/test/fast/Unit tests/nvm_strip_path +++ b/test/fast/Unit tests/nvm_strip_path @@ -9,3 +9,10 @@ TEST_PATH=$NVM_DIR/v0.10.5/bin:/usr/bin:$NVM_DIR/v0.11.5/bin:$NVM_DIR/v0.9.5/bin STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"` [ "$STRIPPED_PATH" = "/usr/bin:/usr/local/bin" ] || die "Not correctly stripped: $STRIPPED_PATH " + +NVM_DIR='/#*.^$[]' +TEST_PATH="$NVM_DIR/v0.10.5/bin:/usr/bin:$NVM_DIR/v0.11.5/bin:$NVM_DIR/v0.9.5/bin:/usr/local/bin:$NVM_DIR/v0.2.5/bin:$NVM_DIR/versions/node/v0.12.0/bin:$NVM_DIR/versions/io.js/v1.0.0/bin" + +STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"` + +[ "$STRIPPED_PATH" = "/usr/bin:/usr/local/bin" ] || die "Not correctly stripped: $STRIPPED_PATH "