Skip to content

Commit bba70f5

Browse files
[Fix] Improve .nvmrc reading process, fix #1015, fix #1712
1 parent f290ccf commit bba70f5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

nvm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ nvm_rc_version() {
293293
nvm_err "No .nvmrc file found"
294294
return 1
295295
fi
296-
read -r NVM_RC_VERSION < "${NVMRC_PATH}" || printf ''
296+
NVM_RC_VERSION="$(command head -n 1 "${NVMRC_PATH}" | command tr -d '\r')" || printf ''
297297
if [ ! -n "${NVM_RC_VERSION}" ]; then
298298
nvm_err "Warning: empty .nvmrc file found at \"${NVMRC_PATH}\""
299299
return 2
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
set -ex
4+
5+
die () { echo "$@" ; cleanup ; exit 1; }
6+
7+
cleanup() {
8+
unset VERSION1 VERSION2
9+
rm -rf .nvmrc
10+
}
11+
12+
\. ../../nvm.sh
13+
14+
# normal .nvmrc
15+
printf '0.999.0\n' > .nvmrc
16+
nvm_rc_version
17+
VERSION1="${NVM_RC_VERSION}"
18+
19+
# .nvmrc with CR char
20+
printf '0.999.0\r\n' > .nvmrc
21+
nvm_rc_version
22+
VERSION2="${NVM_RC_VERSION}"
23+
24+
[ "${VERSION1}" = "${VERSION2}" ]

0 commit comments

Comments
 (0)