Skip to content

Incorrect handling of quoted & escaped parameters for Fish completions #2995

@HansLehnert

Description

@HansLehnert

Completions for parameters in quotes, partially quoted or with escaped characters (e.g. whitespace) don't work properly for Fish shell.

I believe the issue is that for fish completion, the incomplete paramater is passed through the COMP_CWORD environment variable and it's expected that it will be contained in COMP_WORDS as the last parameter. However, before doing this match COMP_WORDS is parsed, which quotes and unescapes the parameters, while COMP_CWORD is not causing the match to fail. See code here.

How to replicate

Consider the following command

@click.command()
@click.argument('bar', type=click.Choice(('hello world',)))
def main(bar: str):
    pass

Trying to complete foo hello in Fish will correctly return completion for foo hello\ world.

The following incomplete commands will not return any completions

  • foo hello\
  • foo "hello
  • foo "hello"

Environment:

  • Python version: 3.13.5
  • Click version: 8.2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions