From ea9214bb2e80117ae4c48f349f0c6451ae2986a9 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Mon, 24 Mar 2014 18:15:40 +0900 Subject: [PATCH] ignores carriage returns --- libexec/pyenv-version-file-read | 6 +++--- test/version-file-read.bats | 26 ++++++++++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/libexec/pyenv-version-file-read b/libexec/pyenv-version-file-read index d3325646..b5ec2c81 100755 --- a/libexec/pyenv-version-file-read +++ b/libexec/pyenv-version-file-read @@ -8,14 +8,14 @@ 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") ) versions=("${words[@]}") if [ -n "$versions" ]; then OLDIFS="$IFS" - { IFS=: - echo "${versions[*]}" - } + IFS=: + echo "${versions[*]}" IFS="$OLDIFS" exit fi diff --git a/test/version-file-read.bats b/test/version-file-read.bats index 851505d2..7b08ece3 100644 --- a/test/version-file-read.bats +++ b/test/version-file-read.bats @@ -24,39 +24,39 @@ setup() { } @test "reads simple version file" { - cat > my-version <<<"3.3.3" + cat > my-version <<<"3.3.5" run pyenv-version-file-read my-version - assert_success "3.3.3" + assert_success "3.3.5" } @test "ignores leading spaces" { - cat > my-version <<<" 3.3.3" + cat > my-version <<<" 3.3.5" run pyenv-version-file-read my-version - assert_success "3.3.3" + assert_success "3.3.5" } @test "reads only the first word from file" { - cat > my-version <<<"3.3.3-p194@tag 2.7.6 hi" + cat > my-version <<<"3.3.5 2.7.6 hi" run pyenv-version-file-read my-version - assert_success "3.3.3-p194@tag:2.7.6:hi" + assert_success "3.3.5:2.7.6:hi" } @test "loads only the first line in file" { cat > my-version < my-version < my-version <<< $'3.3.5\r' + run pyenv-version-file-read my-version + assert_success "3.3.5" +}