Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,15 @@ nvm_remote_version() {
else
VERSION="$(NVM_LTS="${NVM_LTS-}" nvm_remote_versions "${PATTERN}" | command tail -1)"
fi

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}')"
if ! nvm_echo "${VERSION_NUM}" | nvm_grep -q "${PATTERN}"; then
VERSION='N/A'
fi
fi

if [ -n "${NVM_VERSION_ONLY-}" ]; then
command awk 'BEGIN {
n = split(ARGV[1], a);
Expand Down
20 changes: 20 additions & 0 deletions test/fast/Unit tests/nvm_remote_version
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,24 @@ EXIT_CODE="$(nvm_remote_version node >/dev/null 2>&1 ; echo $?)"
|| die "nvm_remote_version node did not return contents of nvm_ls_remote node; got $OUTPUT"
[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version node did not exit with 0, got $EXIT_CODE"

# Test LTS name rejection (Issue #3474)
# When nvm_remote_versions returns a line with LTS name in description,
# nvm_remote_version should reject it if the pattern doesn't match the version number

nvm_remote_versions() {
echo "v4.9.1 Argon *"
}
OUTPUT="$(nvm_remote_version Argon)"
EXIT_CODE="$(nvm_remote_version Argon >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_N/A" ] || die "nvm_remote_version Argon should return N/A (LTS name not in version), got $OUTPUT"
[ "_$EXIT_CODE" = "_3" ] || die "nvm_remote_version Argon should exit with code 3, got $EXIT_CODE"

nvm_remote_versions() {
echo "v4.9.1"
}
OUTPUT="$(nvm_remote_version 4)"
EXIT_CODE="$(nvm_remote_version 4 >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_v4.9.1" ] || die "nvm_remote_version 4 should return v4.9.1, got $OUTPUT"
[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version 4 should exit with code 0, got $EXIT_CODE"

cleanup
Loading