From c314f1cbb3c301c587a4e4f96511d31f1134ffd1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 4 Nov 2026 11:17:14 -0600 Subject: [PATCH] [readme] `cdnvm`: let nvm parse `.nvmrc`, so a symlinked `.nvmrc`'s content is not printed The bash `cdnvm` example read `.nvmrc` raw and passed its content to `nvm ls`, `nvm install`, and `nvm use`, so a `.nvmrc` symlinked to any readable file had that file's content printed in a "not found" error, bypassing the protection that `nvm_process_nvmrc` gives `nvm use`. It now gets the version from `nvm_process_nvmrc`, which refuses a symlinked `.nvmrc` that does not contain a version or alias without showing its content, and also strips comments, which the raw read passed along. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ae0b36a..2b05fef0 100644 --- a/README.md +++ b/README.md @@ -814,7 +814,9 @@ cdnvm() { fi elif [[ -s "${nvm_path}/.nvmrc" && -r "${nvm_path}/.nvmrc" ]]; then declare nvm_version - nvm_version=$(<"${nvm_path}"/.nvmrc) + # Let nvm parse `.nvmrc`, so that comments are ignored and the content of an invalid + # or symlinked `.nvmrc` is not passed along to other nvm commands, which may print it + nvm_version="$(nvm_process_nvmrc "${nvm_path}/.nvmrc")" || return declare locally_resolved_nvm_version # `nvm ls` will check all locally-available versions