From 82c2977813c0a28201379c141e0de7d092b1adf1 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 7 Nov 2023 09:35:02 +0900 Subject: [PATCH 1/5] test: fix typo in method name --- tests/system/HTTP/IncomingRequestTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/HTTP/IncomingRequestTest.php b/tests/system/HTTP/IncomingRequestTest.php index 3855a4b85c94..0211dccacef6 100644 --- a/tests/system/HTTP/IncomingRequestTest.php +++ b/tests/system/HTTP/IncomingRequestTest.php @@ -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/'; From ee34dcaedb1af465124a8fb72135ee5dd0e32b7f Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 7 Nov 2023 09:36:46 +0900 Subject: [PATCH 2/5] test: rename test method --- tests/system/HTTP/IncomingRequestTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/HTTP/IncomingRequestTest.php b/tests/system/HTTP/IncomingRequestTest.php index 0211dccacef6..4830837c1fb6 100644 --- a/tests/system/HTTP/IncomingRequestTest.php +++ b/tests/system/HTTP/IncomingRequestTest.php @@ -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); From 5e4e13bb59b578267d349ecd46f1a8d3a28a024f Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 7 Nov 2023 09:46:48 +0900 Subject: [PATCH 3/5] test: add test when body is '0' --- tests/system/HTTP/IncomingRequestTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/system/HTTP/IncomingRequestTest.php b/tests/system/HTTP/IncomingRequestTest.php index 4830837c1fb6..cfc26a988857 100644 --- a/tests/system/HTTP/IncomingRequestTest.php +++ b/tests/system/HTTP/IncomingRequestTest.php @@ -856,6 +856,13 @@ public function testGetBodyWithFalseBody(): 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 */ From 05966db888ddd749d1f69e60c11bdf12f2444b8b Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 7 Nov 2023 09:47:42 +0900 Subject: [PATCH 4/5] fix: bug that if body is '0', $this->body will be null --- system/HTTP/IncomingRequest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/system/HTTP/IncomingRequest.php b/system/HTTP/IncomingRequest.php index 079a3b69d02f..307a78d38b4a 100755 --- a/system/HTTP/IncomingRequest.php +++ b/system/HTTP/IncomingRequest.php @@ -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; From 42be01d92566eb2b946435be40b4f26cd84131b9 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 7 Nov 2023 09:51:36 +0900 Subject: [PATCH 5/5] chore: update phpstan-baseline.php --- phpstan-baseline.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 451c925f373a..3cbe5a4732fc 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -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[] = [