-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Fixes multiselect choice question defaults in non-interactive mode #27772
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
[Console] Fixes multiselect choice question defaults in non-interactive mode #27772
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug fixes must be submitted against the lowest branch where they apply
For 2.8? :)
|
||
return $choices[$question->getDefault()]; | ||
return $question->getValidator() ? $question->getValidator()($default) : $default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validator wasn't applied here previously, this looks like a behavior change to me so cannot be part of the patch. Should be submitted as a new feature on master separately.
Hi @chalasr, Thanks for the feedback! The way I see it: The only thing I did in this PR, is made the defaults parameter work in the same way it does in interactive mode. It is not really a behaviour change, but an inconsistency between operation modes which could be considered a bug. Can you provide me some additional feedback? Thanks! |
@veewee The updated code looks the same in 2.8 and 4.1 to me (the PR that introduced the bug is part of 2.8). Am I missing something that makes 2.8 free of this bug? Otherwise, this PR needs to be rebased on 2.8 being the lowest branch where the bug applies. About making use of the validator in non-interactive mode, it potentially changes the return value of the method. Could be considered as a bugfix but anyways I think it should be discussed in a dedicated PR as it is not related to the bug fixed here. |
ping @veewee :) should we close/take over? |
Hi @chalasr, Sorry for the delay. To me, it is not very clear what the type of the 'default' parameter should be. For single options it makes sense to provide a key or name, but for multiple options it makes more sense to just provide the array of defaults instead of a comma separated string of indexes / names. Maybe the validator lookup is just overkill in this case... But that's up to you guys to decide. Besides that, I also do not know which versions this affects and how it should be fixed in the different affected versions. Since I have a lot of open questions about the subject, feel free to take this one over. With kind regards. |
@chalasr Can you take over this one? |
@fabpot PR reworked, ready on my side. |
foreach ($default as $k => $v) { | ||
$v = trim($v); | ||
$default[$k] = isset($choices[$v]) ? $choices[$v] : $v; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Borrowed from https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php#L47 so that it's consistent everywhere
Thank you @veewee. |
…n-interactive mode (veewee) This PR was merged into the 2.8 branch. Discussion ---------- [Console] Fixes multiselect choice question defaults in non-interactive mode | Q | A | ------------- | --- | Branch? | >4.1.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | [This commit](41ffc69) introduced a warning in multiselect mode: ``` PHP Notice: Undefined index: in /tmp/vendor/symfony/console/Helper/QuestionHelper.php on line 52 PHP Stack trace: PHP 1. {main}() /tmp/vendor/phpro/grumphp/bin/grumphp:0 PHP 2. GrumPHP\Console\Application->run() /tmp/vendor/phpro/grumphp/bin/grumphp:31 PHP 3. GrumPHP\Console\Application->run() /tmp/vendor/phpro/grumphp/src/Console/Application.php:240 PHP 4. GrumPHP\Console\Application->doRun() /tmp/vendor/symfony/console/Application.php:145 PHP 5. GrumPHP\Console\Application->doRunCommand() /tmp/vendor/symfony/console/Application.php:262 PHP 6. GrumPHP\Console\Command\ConfigureCommand->run() /tmp/vendor/symfony/console/Application.php:904 PHP 7. GrumPHP\Console\Command\ConfigureCommand->execute() /tmp/vendor/symfony/console/Command/Command.php:251 PHP 8. GrumPHP\Console\Command\ConfigureCommand->buildConfiguration() /tmp/vendor/phpro/grumphp/src/Console/Command/ConfigureCommand.php:95 PHP 9. Symfony\Component\Console\Helper\QuestionHelper->ask() /tmp/vendor/phpro/grumphp/src/Console/Command/ConfigureCommand.php:156 Notice: Undefined index: in /tmp/vendor/symfony/console/Helper/QuestionHelper.php on line 52 ``` This PR fixes this issue by parsing the default value using the built-in validator if available. (which most likely is ...) Commits ------- 099e265 [Console] Fixes multiselect choice question in interactive mode with default values
This commit introduced a warning in multiselect mode:
This PR fixes this issue by parsing the default value using the built-in validator if available. (which most likely is ...)