Skip to content

Shell completion does't parse escaped slashes or spaces correctly #1708

Description

@samschott

When a value with an escape string, for instance my\ file, is passed to a click.ParamType, the incomplete value which is passed to click.ParamType.shell_complete will only be "my\ " instead of my file.

Expected Behavior

import click

@click.command()
@click.argument("name", type=click.Choice(["my file", "my folder", "my\\ file", "other"]))
def cli(name):
    click.echo(name)

if __name__ == '__main__':
    cli()

Completing my\ f should be interpreted as the Python string "my f" and match the first two values.

$ example my\ f<TAB>
my\ file
my\ folder

Actual Behavior

Completing my\ f is interpreted as the string "my\\ f" and matches the third value.

$ example my\ f<TAB>
my\\\ file

Environment

  • Python version: 3.8.6
  • Click version: 8.0.0.dev0

Metadata

Metadata

Assignees

No one assigned

    Labels

    f:completionfeature: shell completion

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions