Skip to content

Commit

Permalink
[Fix] ls-remote: do not match on bare LTS names, eg Argon
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 4, 2025
1 parent 9f520c9 commit 7cd6ab0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 9 additions & 5 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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, "*"
Expand All @@ -1703,7 +1708,6 @@ EOF
}
prev=$10;
}' \
| nvm_grep -w "${PATTERN:-.*}" \
| $SORT_COMMAND; } << EOF
$VERSION_LIST
EOF
Expand Down
7 changes: 7 additions & 0 deletions test/fast/Unit tests/nvm ls-remote
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7cd6ab0

Please sign in to comment.