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 03691be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion zsh_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,7 @@ func zshCompFlagCouldBeSpecifiedMoreThenOnce(f *pflag.Flag) bool {
}

func zshCompQuoteFlagDescription(s string) string {
return strings.Replace(s, "'", `'\''`, -1)
return strings.NewReplacer("'", `'\''`,
"[", `\[`,
"]", `\]`).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 03691be

Please sign in to comment.