Skip to content

Special characters not escaped for zsh completion script #1596

@iyzana

Description

@iyzana

Rust Version

rustc 1.38.0 (625451e37 2019-09-23)

Affected Version of clap

clap 2.33.0

Expected Behavior Summary

Generated Zsh completions correctly complete possible_values even in the presence of characters that have a special meaning for the shell

Actual Behavior Summary

For example, when some string in possible_values contains | (a pipe) the generated completion script fails with

(eval):1: parse error near `|'

when pressing tab for that argument.
That was the problem I ran into. I then tested some other special characters.

A sample of the characters I found to have problems:

  • | breaks completion script (eval):1: parse error near `|'
  • ; splits completion value into two
  • ? makes whole value not show up in completions
  • * makes whole value not show up in completions
  • " breaks completion script (eval):1: unmatched "
  • ` breaks completion script (eval):1: unmatched `
  • $ interpreted as https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html when followed by some other chars
  • # makes whole value not show up in completions

There are more special characters, that need to be escaped. The reproduction from the repo tests against all non control ascii characters and some dollar-something strings.

Steps to Reproduce the issue

  • Clone reproduction repo git clone https://github.com/succcubbus/clap-zsh-completions-repro
  • cd clap-zsh-completions-repro
  • cargo run --release > _clap-zsh-completions-repro
  • Copy _clap-zsh-completions-repro somewhere into the $fpath of the zsh (e.g. /usr/local/share/zsh/site-functions)
  • cargo install --path .
  • rehash; compinit (so the zsh picks up the new binary and completions)
  • Type clap-zsh-completions-repro and try to complete the argument

Sample Code or Link to Sample Code

https://github.com/succcubbus/clap-zsh-completions-repro

Debug output

https://pastebin.com/KU4yd6FR

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-completionArea: completion generatorC-bugCategory: bugE-easyCall for participation: Experience needed to fix: Easy / not much

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions