From 7cd6ab099a1160b1b66f8d8daf67f73a77d5c8c5 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 4 Feb 2025 11:13:28 -0800 Subject: [PATCH] [Fix] `ls-remote`: do not match on bare LTS names, eg `Argon` --- nvm.sh | 14 +++++++++----- test/fast/Unit tests/nvm ls-remote | 7 +++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/nvm.sh b/nvm.sh index 5aba5d463d..5db2ce573a 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1688,10 +1688,15 @@ EOF LTS="${LTS#lts/}" fi - VERSIONS="$({ command awk -v lts="${LTS-}" '{ - if (!$1) { next } - if (lts && $10 ~ /^\-?$/) { next } - if (lts && lts != "*" && tolower($10) !~ tolower(lts)) { next } + VERSIONS="$({ command awk -v lts="${LTS-}" -v pattern="${PATTERN:-.*}" ' + BEGIN { + if (pattern == "") pattern = ".*" + } + { + if (!$1) { next } # skip empty lines + if (lts && $10 ~ /^\-?$/) { next } # skip if LTS wanted, and row is not LTS + if (lts && lts != "*" && tolower($10) !~ tolower(lts)) { next } # skip if LTS filter does not match + if ($1 !~ pattern) { next } # only keep rows matching the pattern if ($10 !~ /^\-?$/) { if ($10 && $10 != prev) { print $1, $10, "*" @@ -1703,7 +1708,6 @@ EOF } prev=$10; }' \ - | nvm_grep -w "${PATTERN:-.*}" \ | $SORT_COMMAND; } << EOF $VERSION_LIST EOF diff --git a/test/fast/Unit tests/nvm ls-remote b/test/fast/Unit tests/nvm ls-remote index af3a0a787c..1aa7f7c21c 100755 --- a/test/fast/Unit tests/nvm ls-remote +++ b/test/fast/Unit tests/nvm ls-remote @@ -88,4 +88,11 @@ OUTPUT="$(nvm ls-remote | sed 's/[ \t]*$//')" EXPECTED_OUTPUT="$(cat "${EXPECTED_OUTPUT_PATH}" | sed 's/[ \t]*$//' )" [ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "bare nvm ls-remote did not output expected sorted versions; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<" +OUTPUT="$(nvm ls-remote Argon 2>&1)" +EXIT_CODE=$? +[ $EXIT_CODE -eq 3 ] || die "nvm ls-remote Argon did not exit 3, got '${EXIT_CODE}'" + +EXPECTED_OUTPUT=" N/A" +[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm ls-remote Argon did not output expected error message; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<" + cleanup