From c4dad5709f7133b136bdda2e5b883169a99809ea Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sat, 12 Sep 2026 20:17:22 +0800 Subject: [PATCH] fix: return an empty string when readline() reaches end-of-file --- system/CLI/InputOutput.php | 10 +++++----- user_guide_src/source/changelogs/v4.7.5.rst | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/system/CLI/InputOutput.php b/system/CLI/InputOutput.php index 782e32d0371d..893b98a24595 100644 --- a/system/CLI/InputOutput.php +++ b/system/CLI/InputOutput.php @@ -46,14 +46,14 @@ public function input(?string $prefix = null): string // @codeCoverageIgnoreStart $prompt = $this->readlinePrompt($prefix, readline_info('library_version')); - if ($prompt !== null) { - return readline($prompt); + if ($prompt === null) { + // The library cannot render the prompt, so write it ourselves and let readline() only read the line. + self::fwrite(STDOUT, $prefix ?? ''); } - // The library cannot render the prompt, so write it ourselves and let readline() only read the line. - self::fwrite(STDOUT, $prefix ?? ''); + $input = readline($prompt); - return readline(); + return $input === false ? '' : $input; // @codeCoverageIgnoreEnd } diff --git a/user_guide_src/source/changelogs/v4.7.5.rst b/user_guide_src/source/changelogs/v4.7.5.rst index 6dee8ee9aa6d..2411600ff426 100644 --- a/user_guide_src/source/changelogs/v4.7.5.rst +++ b/user_guide_src/source/changelogs/v4.7.5.rst @@ -39,6 +39,7 @@ Bugs Fixed - **CLI:** Fixed a bug where pressing backspace in a ``CLI::prompt()`` erased the prompt text when the ``readline`` extension is enabled. The prompt is now passed to ``readline()`` so line redraws repaint it. ANSI color codes in the prompt (e.g., option defaults) are wrapped in readline's non-printing markers under GNU readline so cursor positioning stays accurate. On Windows, where the ``readline`` extension is built on WinEditLine, the prompt is written to STDOUT first because WinEditLine reports no library version and prints ANSI sequences literally. +- **CLI:** Fixed a bug where ``CLI::input()`` and ``CLI::prompt()`` threw a ``TypeError`` when STDIN reached end-of-file (e.g., Ctrl+D) with the ``readline`` extension enabled. An empty string is now returned, matching the behavior without ``readline``. - **CLIRequest:** Fixed a bug where ``parseCommand()`` could throw a TypeError when ``argv`` is missing. - **CodeIgniter:** Fixed a bug where ``gatherOutput()`` could be called twice when ``startController()`` returned a ``ResponseInterface`` (e.g., from filter attributes or closure routes). - **Content Security Policy:** Fixed a bug where empty ``Content-Security-Policy``, ``Content-Security-Policy-Report-Only``, and ``Reporting-Endpoints`` response headers were generated when no corresponding values existed.