Skip to content

Commit 39a0d2f

Browse files
authored
fix: return an empty string when readline() reaches end-of-file (#10542)
1 parent 01fd6ee commit 39a0d2f

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎system/CLI/InputOutput.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ public function input(?string $prefix = null): string
4646
// @codeCoverageIgnoreStart
4747
$prompt = $this->readlinePrompt($prefix, readline_info('library_version'));
4848

49-
if ($prompt !== null) {
50-
return readline($prompt);
49+
if ($prompt === null) {
50+
// The library cannot render the prompt, so write it ourselves and let readline() only read the line.
51+
self::fwrite(STDOUT, $prefix ?? '');
5152
}
5253

53-
// The library cannot render the prompt, so write it ourselves and let readline() only read the line.
54-
self::fwrite(STDOUT, $prefix ?? '');
54+
$input = readline($prompt);
5555

56-
return readline();
56+
return $input === false ? '' : $input;
5757
// @codeCoverageIgnoreEnd
5858
}
5959

‎user_guide_src/source/changelogs/v4.7.5.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Bugs Fixed
4141
- **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.
4242
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.
4343
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.
44+
- **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``.
4445
- **CLIRequest:** Fixed a bug where ``parseCommand()`` could throw a TypeError when ``argv`` is missing.
4546
- **CodeIgniter:** Fixed a bug where ``gatherOutput()`` could be called twice when ``startController()`` returned a ``ResponseInterface`` (e.g., from filter attributes or closure routes).
4647
- **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.

0 commit comments

Comments
 (0)