8000 [Console] Fixed different behaviour of key and value user inputs in multiple choice question by maks-rafalko · Pull Request #22718 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Fixed different behaviour of key and value user inputs in multiple choice question #22718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Question/ChoiceQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private function getDefaultValidator()

if ($multiselect) {
// Check for a separated comma values
if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) {
if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selectedChoices, $matches)) {
throw new \InvalidArgumentException(sprintf($errorMessage, $selected));
}
$selectedChoices = explode(',', $selectedChoices);
Expand Down
31 changes: 31 additions & 0 deletions src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,37 @@ public function simpleAnswerProvider()
);
}

/**
* @dataProvider specialCharacterInMultipleChoice
*/
public function testSpecialCharacterChoiceFromMultipleChoiceList($providedAnswer, $expectedValue)
{
$possibleChoices = array(
'.',
'src',
);

$dialog = new QuestionHelper();
$dialog->setInputStream($this->getInputStream($providedAnswer."\n"));
$helperSet = new HelperSet(array(new FormatterHelper()));
$dialog->setHelperSet($helperSet);

$question = new ChoiceQuestion('Please select the directory', $possibleChoices);
$question->setMaxAttempts(1);
$question->setMultiselect(true);
$answer = $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);

$this->assertSame($expectedValue, $answer);
}

public function specialCharacterInMultipleChoice()
{
return array(
array('.', array('.')),
array('., src', array('.', 'src')),
);
}

/**
* @dataProvider mixedKeysChoiceListAnswerProvider
*/
Expand Down
0