mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-02-04 17:02:48 +08:00
[Fix] prevent sed errors when pattern contains #
When `.nvmrc` or alias files contained comments (lines with `#`), the `#` character could end up in the search pattern passed to sed, causing "unterminated regular expression" errors because `#` is used as the sed address delimiter. This commit fixes the issue in two places: 1. `nvm_alias`: Strip comments from alias file contents before returning them, and trim trailing whitespace 2. `nvm_ls`: Escape `#` characters in SEARCH_PATTERN so they're treated as literal characters in the sed address Fixes #3761
This commit is contained in:
4
nvm.sh
4
nvm.sh
@@ -1294,7 +1294,7 @@ nvm_alias() {
|
||||
return 2
|
||||
fi
|
||||
|
||||
command awk 'NF' "${NVM_ALIAS_PATH}"
|
||||
command sed 's/#.*//; s/[[:space:]]*$//' "${NVM_ALIAS_PATH}" | command awk 'NF'
|
||||
}
|
||||
|
||||
nvm_ls_current() {
|
||||
@@ -1529,7 +1529,7 @@ nvm_ls() {
|
||||
PATTERN='v'
|
||||
SEARCH_PATTERN='.*'
|
||||
else
|
||||
SEARCH_PATTERN="$(nvm_echo "${PATTERN}" | command sed 's#\.#\\\.#g;')"
|
||||
SEARCH_PATTERN="$(nvm_echo "${PATTERN}" | command sed 's#\.#\\\.#g; s|#|\\#|g')"
|
||||
fi
|
||||
if [ -n "${NVM_DIRS_TO_SEARCH1}${NVM_DIRS_TO_SEARCH2}${NVM_DIRS_TO_SEARCH3}" ]; then
|
||||
VERSIONS="$(command find "${NVM_DIRS_TO_SEARCH1}"/* "${NVM_DIRS_TO_SEARCH2}"/* "${NVM_DIRS_TO_SEARCH3}"/* -name . -o -type d -prune -o -path "${PATTERN}*" \
|
||||
|
||||
Reference in New Issue
Block a user