From 630fa0971aa3e81dd98e6f70dca4c7ce304428b8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 28 Oct 2023 12:59:00 +0200 Subject: [PATCH] Add break to prevent endless recursion loop --- .../framework/src/Console/Concerns/BetterChoiceHelper.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/framework/src/Console/Concerns/BetterChoiceHelper.php b/packages/framework/src/Console/Concerns/BetterChoiceHelper.php index 772eb1aefde..e42d5d0774d 100644 --- a/packages/framework/src/Console/Concerns/BetterChoiceHelper.php +++ b/packages/framework/src/Console/Concerns/BetterChoiceHelper.php @@ -5,6 +5,7 @@ namespace Hyde\Console\Concerns; use Closure; +use RuntimeException; use Symfony\Component\Console\Helper\Helper; use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Output\NullOutput; @@ -53,6 +54,11 @@ protected function betterChoice(string $question, array $choices, int|string $de $selection = $choices[$answer] ?? null; if ($selection === null) { + // High enough to not impact normal usage, but low enough to break loops + if ($this->retryCount > 30) { + throw new RuntimeException('Maximum retries exceeded'); + } + $this->retryCount++; $this->output->error(sprintf('Invalid option "%s"', $answer)); $this->betterChoice(...func_get_args());