Make sure we quote brackets when generating zsh completion

Signed-off-by: Chmouel Boudjnah <chmouel@chmouel.com>
This commit is contained in:
Chmouel Boudjnah 2019-07-04 16:16:22 +02:00
parent 89c7ffb512
commit 8d84e2e222
No known key found for this signature in database
GPG key ID: 8E00E7B02807E02D
2 changed files with 14 additions and 1 deletions

View file

@ -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)
}

View file

@ -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 {