From caa4a8e228808b7e3dc1fdaf11c3d2ebac30296a Mon Sep 17 00:00:00 2001 From: Jeffrey 'jf' Lim Date: Mon, 23 Sep 2013 14:16:15 +0800 Subject: [PATCH] fix rehash when paths have spaces in them fixes #450 --- libexec/rbenv-rehash | 4 ++-- test/rehash.bats | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index b220329a..5ec195ec 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -82,9 +82,9 @@ remove_outdated_shims() { # registered for installation as a shim. In this way, plugins may call # `make_shims` with a glob to register many shims at once. make_shims() { - local shims="$@" + local shims=("$@") - for file in $shims; do + for file in "${shims[@]}"; do local shim="${file##*/}" register_shim "$shim" done diff --git a/test/rehash.bats b/test/rehash.bats index afcc11cd..97414410 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -53,6 +53,38 @@ ruby OUT } +@test "removes stale shims" { + mkdir -p "${RBENV_ROOT}/shims" + touch "${RBENV_ROOT}/shims/oldshim1" + chmod +x "${RBENV_ROOT}/shims/oldshim1" + + create_executable "2.0" "rake" + create_executable "2.0" "ruby" + + run rbenv-rehash + assert_success "" + + assert [ ! -e "${RBENV_ROOT}/shims/oldshim1" ] +} + +@test "binary install locations containing spaces" { + create_executable "dirname1 p247" "ruby" + create_executable "dirname2 preview1" "rspec" + + assert [ ! -e "${RBENV_ROOT}/shims/ruby" ] + assert [ ! -e "${RBENV_ROOT}/shims/rspec" ] + + run rbenv-rehash + assert_success "" + + run ls "${RBENV_ROOT}/shims" + assert_success + assert_output <