Skip to content

Commit

Permalink
Add test for NVM_DIR outside nvm.sh
Browse files Browse the repository at this point in the history
Fix symlink traversal
  • Loading branch information
msaladna committed Dec 10, 2023
1 parent d956279 commit ad4fa37
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nvm-exec
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash

SOURCE=${BASH_SOURCE[0]}
test -L "$SOURCE" && SOURCE=$(readlink "$SOURCE")
test -L "$SOURCE" && command cd "$( dirname "$SOURCE" )" && \
SOURCE=$(readlink "$SOURCE")
DIR="$(command cd "$( dirname "$SOURCE" )" && pwd )"

unset NVM_CD_FLAGS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

set -ex

die () { echo "$@" ; exit 1; }

INSTPATH="$(mktemp -p "$(pwd)" -d)"
trap 'test ! -z "${INSTPATH-}" && test -d "$INSTPATH" && rm -rf "$INSTPATH"' EXIT
declare -x NVM_DIR=$INSTPATH
\. ../../../nvm.sh

nvm install --lts || die 'nvm install --lts failed'
nvm exec --lts npm --version || die "`nvm exec` failed to run"
declare -x NODE_VERSION="$(nvm exec --lts --silent node --version)"

ln -s ../../../../nvm-exec "$INSTPATH/nvm-exec" || die "failed to create a symlink to $INSTPATH/"
"$INSTPATH/nvm-exec" npm ls > /dev/null || die "`nvm exec` failed to run using nvm-exec helper"

0 comments on commit ad4fa37

Please sign in to comment.