Skip to content

[Fix] Parse commented nvmrc content in nvm_ls#3854

Merged
ljharb merged 2 commits into
nvm-sh:masterfrom
sjh9714:fix-nvmrc-comment-pattern
Jul 9, 2026
Merged

[Fix] Parse commented nvmrc content in nvm_ls#3854
ljharb merged 2 commits into
nvm-sh:masterfrom
sjh9714:fix-nvmrc-comment-pattern

Conversation

@sjh9714

@sjh9714 sjh9714 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3761.

The documented shell integrations pass raw .nvmrc contents to nvm version. When those contents include comments, nvm_ls used the raw value in its sed search expression, which could trigger an unterminated regular expression error. This reuses the .nvmrc parser for commented or multiline patterns before local version matching.

Changes

  • Split .nvmrc content parsing into nvm_process_nvmrc_content.
  • Normalize raw commented or multiline .nvmrc patterns in nvm_ls.
  • Extend the existing hash-pattern regression test to cover raw .nvmrc content through nvm_ls and nvm_version.

Testing

  • for shell in sh bash dash zsh; do printf '== %s ==\n' "$shell"; "$shell" './nvm_ls handles hash in pattern' || exit $?; done
  • for shell in sh bash dash zsh; do printf '== %s ==\n' "$shell"; "$shell" './nvm_process_nvmrc' || exit $?; done
  • for shell in sh bash dash zsh; do printf '== %s ==\n' "$shell"; "$shell" './nvm_version' || exit $?; done
  • for shell in bash dash zsh; do printf '== %s -n ==\n' "$shell"; "$shell" -n nvm.sh || exit $?; done
  • npm run test:check-nonexec
  • git diff --check

Note: I used Codex while preparing this change, reviewed the final diff, and ran the listed checks locally.

Fixes nvm-sh#3761

Signed-off-by: jinhyuk9714 <jinhyuk9714@gmail.com>
@slow6r

This comment was marked as spam.

…R, cover the sed path

- `cleanup` unset TEST_DIR before `rm -rf "${TEST_DIR-}"`, so the temp dir (with an executable fake `node`) was never removed,
and urchin executes any executable file it finds under the test dir on the next local run.
- the preexisting `foo#bar` assertions ran against the ambient NVM_DIR;
now that `#` patterns comment-strip to `foo`, a real local alias named `foo` would resolve and break them,
so all assertions now run against an isolated NVM_DIR.
- the multiline content used a full x.y.z version, which takes nvm_ls's explicit-version fast path and never reaches the find/sed pipeline where the newline actually broke sed;
a partial version exercises that path, and matching on "unterminated" covers both the BSD and GNU sed error wordings.
@ljharb ljharb force-pushed the fix-nvmrc-comment-pattern branch from d886cca to 21d33ef Compare July 9, 2026 21:28
@ljharb ljharb merged commit 21d33ef into nvm-sh:master Jul 9, 2026
210 of 212 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unterminated regular expression with .nvmrc with comments

3 participants