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

This commit is contained in:
borNfreee 2017-05-15 23:51:36 +03:00 committed by Fabien Potencier
parent c4abc1566d
commit 2861bd7b01
2 changed files with 32 additions and 1 deletions

View File

@ -135,7 +135,7 @@ class ChoiceQuestion extends Question
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);

View File

@ -273,6 +273,37 @@ class QuestionHelperTest extends TestCase
);
}
/**
* @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
*/