From ca6690a63ed6db23f3a969b693cd5ebf98906810 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..d871fb8a79b0b 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 '' === $answer || $answerIsTrue; }; } } diff --git a/src/Symfony/Component/Console/Tests/Question/ConfirmationQuestionTest.php b/src/Symfony/Component/Console/Tests/Question/ConfirmationQuestionTest.php index b8aecaa0d852e..83899772a82db 100644 --- a/src/Symfony/Component/Console/Tests/Question/ConfirmationQuestionTest.php +++ b/src/Symfony/Component/Console/Tests/Question/ConfirmationQuestionTest.php @@ -41,7 +41,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"', ],