mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-08-25 00:00:22 +08:00
[Fix] nvm_resolve_local_alias: avoid using variable as printf format string
Using a variable as the format string means `%` characters in alias names would be interpreted as format specifiers. Use `%b` format with the variable as an argument to safely interpret `\n` escapes. Bug introduced in https://github.com/nvm-sh/nvm/commit/9b91734f0b6a210f0c6655b0cd25ea288d9ae376.
This commit is contained in:
@@ -1368,7 +1368,7 @@ nvm_resolve_alias() {
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if command printf "${SEEN_ALIASES}" | nvm_grep -q -e "^${ALIAS_TEMP}$"; then
|
if command printf '%b' "${SEEN_ALIASES}" | nvm_grep -q -e "^${ALIAS_TEMP}$"; then
|
||||||
ALIAS="∞"
|
ALIAS="∞"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
\. ../../../common.sh
|
||||||
|
|
||||||
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
: nvm.sh
|
||||||
|
\. ../../../../nvm.sh
|
||||||
|
|
||||||
|
# An alias whose name contains % should resolve directly
|
||||||
|
try nvm_resolve_alias 'test-%s-alias'
|
||||||
|
[ "$CAPTURED_EXIT_CODE" = "0" ] || die "nvm_resolve_alias test-%s-alias failed with exit code $CAPTURED_EXIT_CODE"
|
||||||
|
[ "$CAPTURED_STDOUT" = "v0.0.1" ] || die "nvm_resolve_alias test-%s-alias was not v0.0.1; got $CAPTURED_STDOUT"
|
||||||
|
|
||||||
|
# An alias chain that passes through a %-containing alias name should resolve
|
||||||
|
try nvm_resolve_alias test-pct-chain
|
||||||
|
[ "$CAPTURED_EXIT_CODE" = "0" ] || die "nvm_resolve_alias test-pct-chain failed with exit code $CAPTURED_EXIT_CODE"
|
||||||
|
[ "$CAPTURED_STDOUT" = "v0.0.1" ] || die "nvm_resolve_alias test-pct-chain was not v0.0.1; got $CAPTURED_STDOUT"
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
\. ../../../common.sh
|
||||||
|
|
||||||
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
: nvm.sh
|
||||||
|
\. ../../../../nvm.sh
|
||||||
|
|
||||||
|
# An alias whose name contains % should resolve directly
|
||||||
|
try nvm_resolve_local_alias 'test-%s-alias'
|
||||||
|
[ "$CAPTURED_EXIT_CODE" = "0" ] || die "nvm_resolve_local_alias test-%s-alias failed with exit code $CAPTURED_EXIT_CODE"
|
||||||
|
[ "$CAPTURED_STDOUT" = "v0.0.1" ] || die "nvm_resolve_local_alias test-%s-alias was not v0.0.1; got $CAPTURED_STDOUT"
|
||||||
|
|
||||||
|
# An alias chain that passes through a %-containing alias name should resolve
|
||||||
|
try nvm_resolve_local_alias test-pct-chain
|
||||||
|
[ "$CAPTURED_EXIT_CODE" = "0" ] || die "nvm_resolve_local_alias test-pct-chain failed with exit code $CAPTURED_EXIT_CODE"
|
||||||
|
[ "$CAPTURED_STDOUT" = "v0.0.1" ] || die "nvm_resolve_local_alias test-pct-chain was not v0.0.1; got $CAPTURED_STDOUT"
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo v0.0.1 > ../../../../alias/test-%s-alias
|
||||||
|
echo test-%s-alias > ../../../../alias/test-pct-chain
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
rm -f ../../../../alias/test-%s-alias
|
||||||
|
rm -f ../../../../alias/test-pct-chain
|
||||||
Reference in New Issue
Block a user