Prevent attempts to `nvm use` a circular reference.
parent
9b91734f0b
commit
2d529cc8b7
3
nvm.sh
3
nvm.sh
|
@ -821,6 +821,9 @@ nvm() {
|
||||||
echo "System version of node not found." >&2
|
echo "System version of node not found." >&2
|
||||||
return 127
|
return 127
|
||||||
fi
|
fi
|
||||||
|
elif [ "_$VERSION" = "_∞" ]; then
|
||||||
|
echo "The alias \"$2\" leads to an infinite loop. Aborting." >&2
|
||||||
|
return 8
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local NVM_VERSION_DIR
|
local NVM_VERSION_DIR
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die () { echo $@ ; cleanup ; exit 1; }
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
rm -rf ../../alias/foo
|
||||||
|
}
|
||||||
|
|
||||||
|
. ../../nvm.sh
|
||||||
|
|
||||||
|
echo 'foo' > ../../alias/foo
|
||||||
|
|
||||||
|
OUTPUT="$(nvm use foo 2>&1)"
|
||||||
|
EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.'
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|
||||||
|
|| die "'nvm use foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||||
|
|
||||||
|
EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"
|
||||||
|
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE"
|
||||||
|
|
||||||
|
cleanup;
|
||||||
|
|
Loading…
Reference in New Issue