From bc543a928566f8457b07755726e1a1a183ced0bf Mon Sep 17 00:00:00 2001 From: Andreas Grub Date: Fri, 11 Feb 2022 12:12:42 +0100 Subject: [PATCH] Fix quoting in wrapper script The 'eval' introduced in #262 unfortunately breaks command invocations were a parameter contains spaces, such as rg "my pattern with spaces" as it would be called as `rg my pattern with spaces`. This can be fixed using printf. Using parameter extension quoting with ${@@Q} only works with bash >4.4 (but only >4.0 is required). At least the above invocation then works correctly! --- lib/core/wrappers.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/core/wrappers.sh b/lib/core/wrappers.sh index 1fd8696..45206bb 100644 --- a/lib/core/wrappers.sh +++ b/lib/core/wrappers.sh @@ -1,9 +1,9 @@ function create_wrappers() { - mkdir -p ${JUNEST_HOME}/usr/bin_wrappers + mkdir -p "${JUNEST_HOME}/usr/bin_wrappers" - cd ${JUNEST_HOME}/usr/bin + cd "${JUNEST_HOME}/usr/bin" || return 1 for file in * do [[ -x $file ]] || continue @@ -14,21 +14,21 @@ function create_wrappers() { # Arguments inside a variable (i.e. `JUNEST_ARGS`) separated by quotes # are not recognized normally unless using `eval`. More info here: # https://github.com/fsquillace/junest/issues/262 - cat < ${JUNEST_HOME}/usr/bin_wrappers/${file} + cat < "${JUNEST_HOME}/usr/bin_wrappers/${file}" #!/usr/bin/env bash JUNEST_ARGS=\${JUNEST_ARGS:-ns --fakeroot} -eval junest \${JUNEST_ARGS} -- ${file} "\$@" +eval junest "\${JUNEST_ARGS}" -- ${file} "\$(printf "%q" "\$@")" EOF - chmod +x ${JUNEST_HOME}/usr/bin_wrappers/${file} + chmod +x "${JUNEST_HOME}/usr/bin_wrappers/${file}" done # Remove wrappers no longer needed - cd ${JUNEST_HOME}/usr/bin_wrappers + cd "${JUNEST_HOME}/usr/bin_wrappers" || return 1 for file in * do - [[ -e ${JUNEST_HOME}/usr/bin/$file ]] || rm -f $file + [[ -e ${JUNEST_HOME}/usr/bin/$file ]] || rm -f "$file" done }