diff --git a/bin/n b/bin/n index 675b88c..cd31052 100755 --- a/bin/n +++ b/bin/n @@ -1147,6 +1147,8 @@ function get_nvmrc_version() { verbose_log "found" "${filepath}" local version <"${filepath}" read -r version + # remove trailing comment, after # + version="$(echo "${version}" | sed 's/[[:space:]]*#.*//')" verbose_log "read" "${version}" # Translate from nvm aliases case "${version}" in diff --git a/test/tests/version-resolve-auto-nvmrc.bats b/test/tests/version-resolve-auto-nvmrc.bats index a99c7fa..fbe72b7 100644 --- a/test/tests/version-resolve-auto-nvmrc.bats +++ b/test/tests/version-resolve-auto-nvmrc.bats @@ -68,3 +68,11 @@ function setup() { output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION auto)" assert_equal "${output}" "8.11.1" } + +@test "auto .nvmrc, trailing comment" { + local TARGET_VERSION="8.10.0" + cd "${MY_DIR}" + printf "${TARGET_VERSION} # comment" > .nvmrc + output="$(n N_TEST_DISPLAY_LATEST_RESOLVED_VERSION auto)" + assert_equal "${output}" "${TARGET_VERSION}" +}