[Fix] nvm_strip_path: preserve literal backslashes in NVM_DIR
This commit is contained in:
1 parent
5e38bc0cae
commit
8486d07a5e
2 files changed
+8
-1
No files matched your search
@@ -1527,7 +1527,8 @@ nvm_strip_path() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local RESULT
|
local RESULT
|
||||||
RESULT="$(command printf %s "${1-}" | command awk -v NVM_DIR="${NVM_DIR}" -v RS=: '
|
RESULT="$(command printf %s "${1-}" | NVM_DIR="${NVM_DIR}" command awk -v RS=: '
|
||||||
|
BEGIN { NVM_DIR = ENVIRON["NVM_DIR"] }
|
||||||
index($0, NVM_DIR) == 1 {
|
index($0, NVM_DIR) == 1 {
|
||||||
path = substr($0, length(NVM_DIR) + 1)
|
path = substr($0, length(NVM_DIR) + 1)
|
||||||
if (path ~ "^(/versions/[^/]*)?/[^/]*'"${2-}"'.*$") { next }
|
if (path ~ "^(/versions/[^/]*)?/[^/]*'"${2-}"'.*$") { next }
|
||||||
|
|||||||
@@ -23,3 +23,9 @@ TEST_PATH=":/a/b/bin::/c/d/bin:"
|
|||||||
STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"`
|
STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"`
|
||||||
|
|
||||||
[ "$STRIPPED_PATH" = "$TEST_PATH" ] || die "Stripping does not preserve colons: $STRIPPED_PATH "
|
[ "$STRIPPED_PATH" = "$TEST_PATH" ] || die "Stripping does not preserve colons: $STRIPPED_PATH "
|
||||||
|
|
||||||
|
for NVM_DIR in '/tmp/nvm\test' '/tmp/nvm\new' '/tmp/nvm\\dir'; do
|
||||||
|
TEST_PATH="$NVM_DIR/v0.10.5/bin:/usr/bin:$NVM_DIR/versions/node/v22.0.0/bin:$NVM_DIR/versions/io.js/v1.0.0/bin:$NVM_DIR-other/v22.0.0/bin:/usr/local/bin"
|
||||||
|
STRIPPED_PATH=$(nvm_strip_path "$TEST_PATH" '/bin')
|
||||||
|
[ "$STRIPPED_PATH" = "/usr/bin:$NVM_DIR-other/v22.0.0/bin:/usr/local/bin" ] || die "Not correctly stripped with literal backslashes: $STRIPPED_PATH"
|
||||||
|
done
|
||||||
Reference in new issue
Block a user