diff --git a/libexec/rbenv-version-file-read b/libexec/rbenv-version-file-read index cde0ca75..03d2db0c 100755 --- a/libexec/rbenv-version-file-read +++ b/libexec/rbenv-version-file-read @@ -8,6 +8,7 @@ VERSION_FILE="$1" if [ -e "$VERSION_FILE" ]; then # Read the first non-whitespace word from the specified version file. # Be careful not to load it whole in case there's something crazy in it. + IFS="${IFS}"$'\r' words=( $(cut -b 1-1024 "$VERSION_FILE") ) version="${words[0]}" diff --git a/test/version-file-read.bats b/test/version-file-read.bats index 66bd46fa..bf7bf910 100644 --- a/test/version-file-read.bats +++ b/test/version-file-read.bats @@ -64,3 +64,9 @@ IN run rbenv-version-file-read my-version assert_success "1.8.7" } + +@test "ignores carriage returns" { + cat > my-version <<< $'1.9.3\r' + run rbenv-version-file-read my-version + assert_success "1.9.3" +}