[Fix] nvm_ls_remote, nvm_remote_version: match dots between version components literally
The version pattern went to grep with its dots unescaped, so each one matched any character: `20.1` also matched `v2041.0.0`, and `20.1.1` matched `v20.111.1`, so `nvm_remote_version 20.1.1` resolved to `v20.111.1`. Escape each dot that is followed by a digit, keeping any other regex syntax in the pattern, like `v[68]`.
This commit is contained in:
1 parent
699c898671
commit
ed2de88826
2 files changed
+56
-3
No files matched your search
@@ -1359,8 +1359,11 @@ nvm_remote_version() {
|
||||
if [ -n "${PATTERN}" ] && [ "_${VERSION}" != "_N/A" ] && ! nvm_validate_implicit_alias "${PATTERN}" 2>/dev/null; then
|
||||
local VERSION_NUM
|
||||
VERSION_NUM="$(nvm_echo "${VERSION}" | command awk '{print $1}')"
|
||||
# the `v` prefix and the trailing non-digit keep `20` from matching `v10.20.0` or `v200.0.0`
|
||||
if ! nvm_echo "${VERSION_NUM} " | nvm_grep -q -e "$(nvm_ensure_version_prefix "${PATTERN%.}")[^0-9]"; then
|
||||
# the `v` prefix and the trailing non-digit keep `20` from matching `v10.20.0` or `v200.0.0`,
|
||||
# and escaping the dots between version components keeps `20.1.1` from matching `v20.111.1`
|
||||
local VERSION_RE
|
||||
VERSION_RE="$(nvm_ensure_version_prefix "${PATTERN%.}" | command sed 's/\.\([0-9]\)/\\.\1/g')"
|
||||
if ! nvm_echo "${VERSION_NUM} " | nvm_grep -q -e "${VERSION_RE}[^0-9]"; then
|
||||
VERSION='N/A'
|
||||
fi
|
||||
fi
|
||||
@@ -2770,12 +2773,17 @@ nvm_ls_remote_index_tab() {
|
||||
fi
|
||||
|
||||
local VERSIONS
|
||||
local PATTERN_RE
|
||||
PATTERN_RE=''
|
||||
if [ -n "${PATTERN}" ] && [ "${PATTERN}" != '*' ]; then
|
||||
if [ "${FLAVOR}" = 'iojs' ]; then
|
||||
PATTERN="$(nvm_ensure_version_prefix "$(nvm_strip_iojs_prefix "${PATTERN}")")"
|
||||
else
|
||||
PATTERN="$(nvm_ensure_version_prefix "${PATTERN}")"
|
||||
fi
|
||||
# match the dots between version components literally, so that `20.1.1` does not also
|
||||
# match `v20.111.1`; other regex syntax in the pattern (like `v[68]` or `.*`) is kept
|
||||
PATTERN_RE="$(nvm_echo "${PATTERN}" | command sed 's/\.\([0-9]\)/\\.\1/g')"
|
||||
else
|
||||
unset PATTERN
|
||||
fi
|
||||
@@ -2849,7 +2857,7 @@ EOF
|
||||
}
|
||||
prev=$10;
|
||||
}' \
|
||||
| nvm_grep -w -e "${PATTERN:-.*}" \
|
||||
| nvm_grep -w -e "${PATTERN_RE:-.*}" \
|
||||
| $SORT_COMMAND; } << EOF
|
||||
$VERSION_LIST
|
||||
EOF
|
||||
|
||||
Reference in new issue
Block a user