Skip to content

Square brackets in the description causes problems with zsh #1129

@umbynos

Description

@umbynos

I think I found a bug with zsh completion in cobra 1.0.0: If I put square brackets in a command description they do not get escaped correctly causing problems.
Here there's an example of the line causing problems.
I "patched" this behaviour with:

buf := new(bytes.Buffer)
	cmd.Root().GenZshCompletion(buf)
	r := strings.NewReplacer("[", "\\[", "]", "\\]") //insert escaping before [ and ]
	s := r.Replace(buf.String())
	s = strings.ReplaceAll(s, "\\[1\\]", "[1]") // revert the case
	os.Stdout.WriteString(s)

I think this will be fixed in #1070 but I'm opening that just for reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions