Skip to content

valueName's containing colons are not escaped in completion scripts #761

Closed
@edigaryev

Description

@edigaryev

Here's an example of an option from Tart, the option has a valueName that contains a colon:

@Option(help: ArgumentHelp("""
Additional disk attachments with an optional read-only and synchronization options (e.g. --disk="disk.bin", --disk="ubuntu.iso:ro", --disk="/dev/disk0", --disk "ghcr.io/cirruslabs/xcode:16.0:ro" or --disk="nbd://localhost:10809/myDisk:sync=none")
""", valueName: "path[:options]"))
var disk: [String] = []

This is a common notation for Unix-like CLI tools meaning that you can either specify a path, or additionally have options, but after a colon.

The resulting Zsh completion looks like this:

_tart_run() {
    local -i ret=1
    local -ar arg_specs=(
        [...]
        '*--disk[Additional disk attachments with an optional read-only and synchronization options (e.g. --disk="disk.bin", --disk="ubuntu.iso:ro", --disk="/dev/disk0", --disk "ghcr.io/cirruslabs/xcode:16.0:ro" or --disk="nbd://localhost:10809/myDisk:sync=none")]:path[:options]:'
        [...]
    )
    _arguments -w -s -S : "${arg_specs[@]}" && ret=0

    return "${ret}"
}

Here, the colon slips into the completion unescaped, so attempting to complete the tart run --disk results in the following Zsh error:

% tart run --disk _arguments:465: command not found: options]

Happens on the main branch of the ArgumentParser.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions