diff --git a/libexec/rbenv-commands b/libexec/rbenv-commands index 58aab012..daeedd78 100755 --- a/libexec/rbenv-commands +++ b/libexec/rbenv-commands @@ -20,9 +20,11 @@ elif [ "$1" = "--no-sh" ]; then shift fi +IFS=: paths=($PATH) + shopt -s nullglob -{ for path in ${PATH//:/$'\n'}; do +{ for path in "${paths[@]}"; do for command in "${path}/rbenv-"*; do command="${command##*rbenv-}" if [ -n "$sh" ]; then diff --git a/libexec/rbenv-exec b/libexec/rbenv-exec index 45dbbf80..4ccc610c 100755 --- a/libexec/rbenv-exec +++ b/libexec/rbenv-exec @@ -32,7 +32,8 @@ fi RBENV_COMMAND_PATH="$(rbenv-which "$RBENV_COMMAND")" RBENV_BIN_PATH="${RBENV_COMMAND_PATH%/*}" -for script in $(rbenv-hooks exec); do +IFS=$'\n' scripts=(`rbenv-hooks exec`) +for script in "${scripts[@]}"; do source "$script" done diff --git a/libexec/rbenv-hooks b/libexec/rbenv-hooks index 25551782..f81e9af4 100755 --- a/libexec/rbenv-hooks +++ b/libexec/rbenv-hooks @@ -37,9 +37,11 @@ realpath() { cd "$cwd" } +IFS=: hook_paths=($RBENV_HOOK_PATH) + shopt -s nullglob -for path in ${RBENV_HOOK_PATH//:/$'\n'}; do - for script in $path/"$RBENV_COMMAND"/*.bash; do +for path in "${hook_paths[@]}"; do + for script in "$path/$RBENV_COMMAND"/*.bash; do echo $(realpath $script) done done diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 8a6d66d6..fd987ace 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -144,7 +144,8 @@ make_shims ../versions/*/bin/* cd "$OLDPWD" # Allow plugins to register shims. -for script in $(rbenv-hooks rehash); do +IFS=$'\n' scripts=(`rbenv-hooks rehash`) +for script in "${scripts[@]}"; do source "$script" done diff --git a/libexec/rbenv-which b/libexec/rbenv-which index 1301b2ef..393a06e8 100755 --- a/libexec/rbenv-which +++ b/libexec/rbenv-which @@ -63,7 +63,8 @@ else RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}" fi -for script in $(rbenv-hooks which); do +IFS=$'\n' scripts=(`rbenv-hooks which`) +for script in "${scripts[@]}"; do source "$script" done diff --git a/test/commands.bats b/test/commands.bats index 2cac3940..81d38609 100644 --- a/test/commands.bats +++ b/test/commands.bats @@ -19,6 +19,18 @@ load test_helper assert_line "shell" } +@test "commands in path with spaces" { + path="${RBENV_TEST_DIR}/my commands" + cmd="${path}/rbenv-sh-hello" + mkdir -p "$path" + touch "$cmd" + chmod +x "$cmd" + + PATH="${path}:$PATH" run rbenv-commands --sh + assert_success + assert_line "hello" +} + @test "commands --no-sh" { run rbenv-commands --no-sh assert_success diff --git a/test/exec.bats b/test/exec.bats new file mode 100644 index 00000000..0e4852f2 --- /dev/null +++ b/test/exec.bats @@ -0,0 +1,14 @@ +#!/usr/bin/env bats + +load test_helper + +@test "supports hook path with spaces" { + hook_path="${RBENV_TEST_DIR}/custom stuff/rbenv hooks" + mkdir -p "${hook_path}/exec" + echo "export HELLO='from hook'" > "${hook_path}/exec/hello.bash" + + export RBENV_VERSION=system + RBENV_HOOK_PATH="$hook_path" run rbenv-exec env + assert_success + assert_line "HELLO=from hook" +} diff --git a/test/hooks.bats b/test/hooks.bats index bc1b5f17..da450b6a 100644 --- a/test/hooks.bats +++ b/test/hooks.bats @@ -28,6 +28,18 @@ create_hook() { assert_line 2 "${RBENV_TEST_DIR}/etc/rbenv_hooks/exec/bueno.bash" } +@test "supports hook paths with spaces" { + path1="${RBENV_TEST_DIR}/my hooks/rbenv.d" + path2="${RBENV_TEST_DIR}/etc/rbenv hooks" + create_hook "$path1" exec "hello.bash" + create_hook "$path2" exec "ahoy.bash" + + RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec + assert_success + assert_line 0 "${RBENV_TEST_DIR}/my hooks/rbenv.d/exec/hello.bash" + assert_line 1 "${RBENV_TEST_DIR}/etc/rbenv hooks/exec/ahoy.bash" +} + @test "resolves relative paths" { path="${RBENV_TEST_DIR}/rbenv.d" create_hook "$path" exec "hello.bash"