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 84bda8d
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 @@ -83,4 +83,11 @@ EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH")"
OUTPUT="$(NVM_LTS=argon nvm_ls_remote)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "\`NVM_LTS=argon nvm_ls_remote\` did not output >$EXPECTED_OUTPUT<; got >$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 84bda8d

Please sign in to comment.