From 285e72806cb3f1700e1a1977a7f08cc458345334 Mon Sep 17 00:00:00 2001 From: James Hudson Date: Fri, 11 Jan 2019 07:41:03 +0000 Subject: [PATCH] [Console] Fixed #29835: ConfirmationQuestion with default true for answer '0' When using the ConfirmationQuestion class to ask a yes / no question, if the default is true, and the answer regex is '/^y/i', then any value not starting with [yY] is considered false. This must include "0" --- src/Symfony/Component/Console/Question/ConfirmationQuestion.php | 2 +- .../Console/Tests/Question/ConfirmationQuestionTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Console/Question/ConfirmationQuestion.php b/src/Symfony/Component/Console/Question/ConfirmationQuestion.php index 150ab27f303be..86be63ff7caab 100644 --- a/src/Symfony/Component/Console/Question/ConfirmationQuestion.php +++ b/src/Symfony/Component/Console/Question/ConfirmationQuestion.php @@ -53,7 +53,7 @@ private function getDefaultNormalizer() return $answer && $answerIsTrue; } - return !$answer || $answerIsTrue; + return strlen($answer) === 0 || $answerIsTrue; }; } } diff --git a/src/Symfony/Component/Console/Tests/Question/ConfirmationQuestionTest.php b/src/Symfony/Component/Console/Tests/Question/ConfirmationQuestionTest.php index 12d1bee2ae782..e18566eece08a 100644 --- a/src/Symfony/Component/Console/Tests/Question/ConfirmationQuestionTest.php +++ b/src/Symfony/Component/Console/Tests/Question/ConfirmationQuestionTest.php @@ -40,7 +40,7 @@ public function normalizerUsecases() ], [ true, - ['n', 'N', 'no', 'NO', 'nO', 'foo', '1'], + ['n', 'N', 'no', 'NO', 'nO', 'foo', '1', '0'], false, 'When default is true, the normalizer must return false for "%s"', ],