Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2861bd7

Browse files
maks-rafalkofabpot
authored andcommitted
[Console] Fixed different behaviour of key and value user inputs in multiple choice question
1 parent c4abc15 commit 2861bd7

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/Symfony/Component/Console/Question/ChoiceQuestion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private function getDefaultValidator()
135135

136136
if ($multiselect) {
137137
// Check for a separated comma values
138-
if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) {
138+
if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selectedChoices, $matches)) {
139139
throw new \InvalidArgumentException(sprintf($errorMessage, $selected));
140140
}
141141
$selectedChoices = explode(',', $selectedChoices);

src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,37 @@ public function simpleAnswerProvider()
273273
);
274274
}
275275

276+
/**
277+
* @dataProvider specialCharacterInMultipleChoice
278+
*/
279+
public function testSpecialCharacterChoiceFromMultipleChoiceList($providedAnswer, $expectedValue)
280+
{
281+
$possibleChoices = array(
282+
'.',
283+
'src',
284+
);
285+
286+
$dialog = new QuestionHelper();
287+
$dialog->setInputStream($this->getInputStream($providedAnswer."\n"));
288+
$helperSet = new HelperSet(array(new FormatterHelper()));
289+
$dialog->setHelperSet($helperSet);
290+
291+
$question = new ChoiceQuestion('Please select the directory', $possibleChoices);
292+
$question->setMaxAttempts(1);
293+
$question->setMultiselect(true);
294+
$answer = $dialog->ask($this->createInputInterfaceMock(), $this->createOutputInterface(), $question);
295+
296+
$this->assertSame($expectedValue, $answer);
297+
}
298+
299+
public function specialCharacterInMultipleChoice()
300+
{
301+
return array(
302+
array('.', array('.')),
303+
array('., src', array('.', 'src')),
304+
);
305+
}
306+
276307
/**
277308
* @dataProvider mixedKeysChoiceListAnswerProvider
278309
*/

0 commit comments

Comments
 (0)