Closed
Description
Symfony version(s) affected: all
Description
When using ChoiceQuestion with multiselect option, the defaultValidator removes spaces from the input which result in an error "Value [input] is invalid"
How to reproduce
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Style\SymfonyStyle;
class DemoCommand extends Command
{
protected static $defaultName = 'demo';
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->askQuestion(
(new ChoiceQuestion('Question', [
'First response',
'Second response',
]))
->setMultiselect(true)
);
}
}
Possible Solution
Removing the str_replace
from de default validator and using trim on the result of explode instead.
I already prepared a fix with tests. The pull request is coming
Additional context