Skip to content

Commit a3a7134

Browse files
committed
fix: if body is null, should return null
See IncomingRequestTest::testGetJSONReturnsNullFromNullBody()
1 parent 4d2a4ba commit a3a7134

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

system/HTTP/IncomingRequest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,11 @@ public function getVar($index = null, $filter = null, $flags = null)
578578
*/
579579
public function getJSON(bool $assoc = false, int $depth = 512, int $options = 0)
580580
{
581-
$result = json_decode($this->body ?? '', $assoc, $depth, $options);
581+
if ($this->body === null) {
582+
return null;
583+
}
584+
585+
$result = json_decode($this->body, $assoc, $depth, $options);
582586

583587
if (json_last_error() !== JSON_ERROR_NONE) {
584588
throw HTTPException::forInvalidJSON(json_last_error_msg());

0 commit comments

Comments
 (0)