Skip to content

[console] Ambiguous keys get wrongly autocompleted #21789

@dritter

Description

@dritter
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? yes
Symfony version 3.2.4

My situation is as follows:
I have a console application that uses a ChoiceQuestion with version numbers as values. Rendered the question looks like this:

  [0]: 3.0.0
  [1]: 2.2.0
  [2]: 2.1.3

If I select option "2" I'll get "2.2.0", because the value gets autocompleted.

It even fails with associative arrays:

  [a]: berlin
  [b]: copenhagen
  [c]: amsterdam

If I select "b", I get "a", the key of the first option, as its value is found by the autocompleter.

Here is a testcase to demonstrate the behaviour:

    public function testAmbiguousKeyFromChoicelist()
    {
        $possibleChoices = array(
            'a' => 'berlin',
            'b' => 'copenhagen',
            'c' => 'amsterdam',
        );

        $dialog = new QuestionHelper();
        $helperSet = new HelperSet(array(new FormatterHelper()));
        $dialog->setHelperSet($helperSet);

        $question = new ChoiceQuestion('Please select the environment to load', $possibleChoices);
        $question->setMaxAttempts(1);

        $answer = $dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream("b\n")), $this->createOutputInterface(), $question);

        $this->assertSame("b", $answer);
    }

A possible solutions could be:

  • Do not consider keys as autocomplete values (so keys must match exactly)
  • Do consider keys as autocomplete values, but the take precedence over values

My preference would be the first option.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions