Skip to content
Draft
Changes from 3 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
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,14 @@ nvm_do_install() {
if nvm_profile_is_bash_or_zsh "${NVM_PROFILE-}"; then
BASH_OR_ZSH=true
fi
if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then
if ! command grep -qc '^[[:space:]]*[^#].*/nvm\.sh' "$NVM_PROFILE"; then

@ljharb ljharb Jul 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still matches indented comments - [[:space:]]* backtracks, so [^#] can itself match a space: a line like # [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" (or a tab-indented one) is still treated as active, and the #1889 repro persists for it.

Excluding whitespace from the guard class fixes it without breaking indented active lines:

'^[[:space:]]*[^#[:space:]].*/nvm\.sh'

(the $NVM_DIR/bash_completion pattern below has the same issue)

The regression tests should include an indented-comment case, since that is the case that distinguishes this pattern from the correct one.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ljharb will work on the regex fix and will add regression tests.

nvm_echo "=> Appending nvm source string to $NVM_PROFILE"
command printf '%b' "${SOURCE_STR}" >> "$NVM_PROFILE"
else
nvm_echo "=> nvm source string already in ${NVM_PROFILE}"
fi
# shellcheck disable=SC2016
if ${BASH_OR_ZSH} && ! command grep -qc '$NVM_DIR/bash_completion' "$NVM_PROFILE"; then
if ${BASH_OR_ZSH} && ! command grep -qc '^[[:space:]]*[^#].*\$NVM_DIR/bash_completion' "$NVM_PROFILE"; then
nvm_echo "=> Appending bash_completion source string to $NVM_PROFILE"
command printf '%b' "$COMPLETION_STR" >> "$NVM_PROFILE"
else
Expand Down
Loading