diff --git a/system/HTTP/CLIRequest.php b/system/HTTP/CLIRequest.php index 453272a4f59a..67c6ad4c1c7c 100644 --- a/system/HTTP/CLIRequest.php +++ b/system/HTTP/CLIRequest.php @@ -185,7 +185,7 @@ public function getOptionString(bool $useLongOpts = false): string */ protected function parseCommand() { - $args = $this->getServer('argv'); + $args = $this->getServer('argv') ?? []; array_shift($args); // Scrap index.php $optionValue = false; diff --git a/tests/system/HTTP/CLIRequestTest.php b/tests/system/HTTP/CLIRequestTest.php index 0bf3da0a6848..d12889448a30 100644 --- a/tests/system/HTTP/CLIRequestTest.php +++ b/tests/system/HTTP/CLIRequestTest.php @@ -574,4 +574,15 @@ public function testIs(): void { $this->assertFalse($this->request->is('get')); } + + public function testParseCommandWithMissingArgv(): void + { + Services::injectMock('superglobals', new Superglobals([], [], [], [], [])); + + $request = new CLIRequest(new App()); + + $this->assertSame('', $request->getPath()); + $this->assertSame([], $request->getSegments()); + $this->assertSame('', $request->getOptionString()); + } } diff --git a/user_guide_src/source/changelogs/v4.7.5.rst b/user_guide_src/source/changelogs/v4.7.5.rst index 964133046c38..c83924b0d500 100644 --- a/user_guide_src/source/changelogs/v4.7.5.rst +++ b/user_guide_src/source/changelogs/v4.7.5.rst @@ -30,6 +30,7 @@ Deprecations Bugs Fixed ********** +- **CLIRequest:** Fixed a bug where ``parseCommand()`` could throw a TypeError when ``argv`` is missing. - **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. - **Logger:** Fixed a bug where interpolating a log message with array or non-stringable context values could raise PHP warnings or errors.