Skip to content

Commit

Permalink
Make sure we quote brackets when generating zsh completion
Browse files Browse the repository at this point in the history
Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel committed Jul 17, 2019
1 parent 2d7544e commit 4720dca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion zsh_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,6 @@ func zshCompFlagCouldBeSpecifiedMoreThenOnce(f *pflag.Flag) bool {
}

func zshCompQuoteFlagDescription(s string) string {
return strings.Replace(s, "'", `'\''`, -1)
replacer := strings.NewReplacer("'", `'\''`, "[", `\[`, "]", `\]`)
return replacer.Replace(s)
}
11 changes: 11 additions & 0 deletions zsh_completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ func TestGenZshCompletion(t *testing.T) {
`--private\[Don'\\''t show public info]`,
},
},
{
name: "flag description with brackets ([]) shouldn't break the completion file",
root: func() *Command {
r := genTestCommand("root", true)
r.Flags().Bool("level", false, "[ALERT]")
return r
}(),
expectedExpressions: []string{
`--level[\[ALERT\]]`,
},
},
{
name: "argument completion for file with and without patterns",
root: func() *Command {
Expand Down

0 comments on commit 4720dca

Please sign in to comment.