Skip to content

Commit 820a3d6

Browse files
authored
fix: quote arguments for passing to auto completion server (#20)
1 parent d5659d5 commit 820a3d6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/zsh.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,21 @@ _${name}() {
4646
flagPrefix="-P \${BASH_REMATCH}"
4747
fi
4848
49-
# Prepare the command to obtain completions
50-
requestComp="${exec} complete -- \${words[2,-1]}"
49+
# Prepare the command to obtain completions, ensuring arguments are quoted for eval
50+
local -a args_to_quote=("\${(@)words[2,-1]}")
5151
if [ "\${lastChar}" = "" ]; then
5252
# If the last parameter is complete (there is a space following it)
5353
# We add an extra empty parameter so we can indicate this to the go completion code.
5454
__${name}_debug "Adding extra empty parameter"
55-
requestComp="\${requestComp} ''"
55+
args_to_quote+=("")
5656
fi
5757
58+
# Use Zsh's (q) flag to quote each argument safely for eval
59+
local quoted_args=("\${(@q)args_to_quote}")
60+
61+
# Join the main command and the quoted arguments into a single string for eval
62+
requestComp="${exec} complete -- \${quoted_args[*]}"
63+
5864
__${name}_debug "About to call: eval \${requestComp}"
5965
6066
# Use eval to handle any environment variables and such

0 commit comments

Comments
 (0)