From 0de6910d1f99c9576f8c2e5a916644fed99cddb5 Mon Sep 17 00:00:00 2001 From: Jean-Paul Bonnetouche Date: Wed, 13 Jan 2021 12:47:03 +0100 Subject: [PATCH] fix: shims break when POSIXLY_CORRECT=1 Process substitution isn't specified by POSIX and makes shims break when called by a script that `export POSIXLY_CORRECT=1` (like gitflow [here](https://github.com/nvie/gitflow/blob/develop/git-flow#L78)). Here we replace `grep -f <(cmd1) <(cmd2)` with `cmd2 | grep -F "$(cmd1)"` so that we can provide a string instead of a file descriptor and get the same result as before. (Note: We also check if the result of `cmd1` is empty before running `grep` to get the same behavior as with `-f`. This also prevent crashes if null results are piped to `xargs` and fits nicely with the `with_shim_executable` function that already check the result of `$selected_version` before going on). Fixes: #581 --- lib/utils.bash | 5 ++++- test/shim_exec.bats | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/utils.bash b/lib/utils.bash index ce8360af..ee200057 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -663,7 +663,10 @@ preset_versions() { select_from_preset_version() { shim_name=$1 - grep -f <(get_shim_versions "$shim_name") <(preset_versions "$shim_name") | head -n 1 | xargs -IVERSION printf "%s\\n" VERSION + shim_versions=$(get_shim_versions "$shim_name") + if [ -n "$shim_versions" ]; then + preset_versions "$shim_name" | grep -F "$shim_versions" | head -n 1 | xargs -IVERSION printf "%s\\n" VERSION + fi } select_version() { diff --git a/test/shim_exec.bats b/test/shim_exec.bats index ffa5bd39..4a40c4be 100644 --- a/test/shim_exec.bats +++ b/test/shim_exec.bats @@ -436,3 +436,15 @@ EOM [ "$status" -eq 1 ] } +# From @tejanium in https://github.com/asdf-vm/asdf/issues/581#issuecomment-635337727 +@test "asdf exec should not crash when POSIXLY_CORRECT=1" { + export POSIXLY_CORRECT=1 + + echo "dummy 1.0" > $PROJECT_DIR/.tool-versions + run asdf install + + run asdf exec dummy world hello + echo $output + [ "$output" == "This is Dummy 1.0! hello world" ] + [ "$status" -eq 0 ] +}