Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 6,
'count' => 5,
'path' => __DIR__ . '/system/HTTP/IncomingRequest.php',
];
$ignoreErrors[] = [
Expand Down
7 changes: 6 additions & 1 deletion system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,14 @@ public function __construct($config, ?URI $uri = null, $body = 'php://input', ?U
$body = file_get_contents('php://input');
}

// If file_get_contents() returns false or empty string, set null.
if ($body === false || $body === '') {
$body = null;
}

$this->config = $config;
$this->uri = $uri;
$this->body = ! empty($body) ? $body : null;
$this->body = $body;
$this->userAgent = $userAgent;
$this->validLocales = $config->supportedLocales;

Expand Down
11 changes: 9 additions & 2 deletions tests/system/HTTP/IncomingRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public function testGetJsonVarReturnsNullFromNullBody(): void
$this->assertNull($request->getJsonVar('myKey'));
}

public function testgetJSONReturnsNullFromNullBody(): void
public function testGetJSONReturnsNullFromNullBody(): void
{
$config = new App();
$config->baseURL = 'http://example.com/';
Expand Down Expand Up @@ -847,7 +847,7 @@ public function testGetPostSecondStreams(): void
$this->assertSame(array_merge($_POST, $_GET), $this->request->getGetPost());
}

public function testWithFalseBody(): void
public function testGetBodyWithFalseBody(): void
{
// Use `false` here to simulate file_get_contents returning a false value
$request = $this->createRequest(null, false);
Expand All @@ -856,6 +856,13 @@ public function testWithFalseBody(): void
$this->assertNull($request->getBody());
}

public function testGetBodyWithZero(): void
{
$request = $this->createRequest(null, '0');

$this->assertSame('0', $request->getBody());
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/3020
*/
Expand Down