From 69ff2d0c9a4fd273c9dac151345f60f7b146e569 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Tue, 2 Nov 2021 06:48:26 -0700 Subject: [PATCH] fix: Quote commands correctly in plugin-test (#1078) * fix: Quote commands correctly in plugin-test * make it posix compliant * default to $SHELL --- lib/commands/command-plugin-test.bash | 65 +++++++++++++++------------ 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/lib/commands/command-plugin-test.bash b/lib/commands/command-plugin-test.bash index a4a542655..07d518270 100644 --- a/lib/commands/command-plugin-test.bash +++ b/lib/commands/command-plugin-test.bash @@ -2,35 +2,42 @@ plugin_test_command() { - local plugin_name=$1 - local plugin_url=$2 - local plugin_command_array=() - local plugin_command + local plugin_name="$1" + local plugin_url="$2" + shift 2 + local plugin_gitref="master" local tool_version - # shellcheck disable=SC2086 - set -- ${*:3} - - while [[ $# -gt 0 ]]; do - case $1 in - --asdf-plugin-gitref) - plugin_gitref="$2" - shift # past flag - shift # past value - ;; - --asdf-tool-version) - tool_version="$2" - shift # past flag - shift # past value - ;; - *) - plugin_command_array+=("$1") # save it in an array for later - shift # past argument - ;; - esac + local interpret_args_literally + + for arg; do + shift + if [ -n "${interpret_args_literally}" ]; then + set -- "$@" "${arg}" + else + case "${arg}" in + --asdf-plugin-gitref) + plugin_gitref="$2" + shift 2 + ;; + --asdf-tool-version) + tool_version="$2" + shift 2 + ;; + --) + interpret_args_literally=true + shift + ;; + *) + set -- "$@" "${arg}" + ;; + esac + fi done - plugin_command="${plugin_command_array[*]}" + if [ "$#" -eq 1 ]; then + set -- "${SHELL:-sh}" -c "$1" + fi local exit_code local TEST_DIR @@ -128,11 +135,11 @@ plugin_test_command() { fail_test "could not reshim plugin" fi - if [ -n "$plugin_command" ]; then - $plugin_command + if [ "$#" -gt 0 ]; then + "$@" exit_code=$? if [ $exit_code != 0 ]; then - fail_test "$plugin_command failed with exit code $?" + fail_test "$* failed with exit code $?" fi fi @@ -155,7 +162,7 @@ plugin_test_command() { } # run test in a subshell - (plugin_test) + (plugin_test "$@") exit_code=$? rm -rf "$TEST_DIR" exit $exit_code