From 8ae36f3cdc57cce28c9cbef4e0541830cc79a2dc Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Thu, 25 May 2023 14:34:50 +0200 Subject: [PATCH] [Console] block input stream if needed When the input stream used in the question helper is not blocking, the default value is always used as the stream return false. In order to fix that, we force the stream to be in blocking state and go back to the old state after so other logic is not impacted by this change --- .../Component/Console/Helper/QuestionHelper.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Symfony/Component/Console/Helper/QuestionHelper.php b/src/Symfony/Component/Console/Helper/QuestionHelper.php index ec5b418f2cbe7..e236be92a3913 100644 --- a/src/Symfony/Component/Console/Helper/QuestionHelper.php +++ b/src/Symfony/Component/Console/Helper/QuestionHelper.php @@ -128,7 +128,18 @@ private function doAsk(OutputInterface $output, Question $question) } if (false === $ret) { + $isBlocked = stream_get_meta_data($inputStream)['blocked'] ?? true; + + if (!$isBlocked) { + stream_set_blocking($inputStream, true); + } + $ret = $this->readInput($inputStream, $question); + + if (!$isBlocked) { + stream_set_blocking($inputStream, false); + } + if (false === $ret) { throw new MissingInputException('Aborted.'); }