Skip to content

Commit 2a30043

Browse files
authored
fix: resolve TypeError in CLIRequest::parseCommand when argv is missing (#10415)
1 parent aa7f6bb commit 2a30043

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

system/HTTP/CLIRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function getOptionString(bool $useLongOpts = false): string
185185
*/
186186
protected function parseCommand()
187187
{
188-
$args = $this->getServer('argv');
188+
$args = $this->getServer('argv') ?? [];
189189
array_shift($args); // Scrap index.php
190190

191191
$optionValue = false;

tests/system/HTTP/CLIRequestTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,4 +574,15 @@ public function testIs(): void
574574
{
575575
$this->assertFalse($this->request->is('get'));
576576
}
577+
578+
public function testParseCommandWithMissingArgv(): void
579+
{
580+
Services::injectMock('superglobals', new Superglobals([], [], [], [], []));
581+
582+
$request = new CLIRequest(new App());
583+
584+
$this->assertSame('', $request->getPath());
585+
$this->assertSame([], $request->getSegments());
586+
$this->assertSame('', $request->getOptionString());
587+
}
577588
}

user_guide_src/source/changelogs/v4.7.5.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Deprecations
3030
Bugs Fixed
3131
**********
3232

33+
- **CLIRequest:** Fixed a bug where ``parseCommand()`` could throw a TypeError when ``argv`` is missing.
3334
- **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.
3435
- **Logger:** Fixed a bug where interpolating a log message with array or non-stringable context values could raise PHP warnings or errors.
3536

0 commit comments

Comments
 (0)