Skip to content

fix: quote arguments for passing to auto completion server #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/zsh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,21 @@ _${name}() {
flagPrefix="-P \${BASH_REMATCH}"
fi

# Prepare the command to obtain completions
requestComp="${exec} complete -- \${words[2,-1]}"
# Prepare the command to obtain completions, ensuring arguments are quoted for eval
local -a args_to_quote=("\${(@)words[2,-1]}")
if [ "\${lastChar}" = "" ]; then
# If the last parameter is complete (there is a space following it)
# We add an extra empty parameter so we can indicate this to the go completion code.
__${name}_debug "Adding extra empty parameter"
requestComp="\${requestComp} ''"
args_to_quote+=("")
fi

# Use Zsh's (q) flag to quote each argument safely for eval
local quoted_args=("\${(@q)args_to_quote}")

# Join the main command and the quoted arguments into a single string for eval
requestComp="${exec} complete -- \${quoted_args[*]}"

__${name}_debug "About to call: eval \${requestComp}"

# Use eval to handle any environment variables and such
Expand Down