From 3f1a71b412a00d359fe546d6e5982d2899d49a05 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 9 Dec 2023 20:37:23 +0900 Subject: [PATCH] fix: DEPRECATED error in Honeypot [DEPRECATED] str_ireplace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in SYSTEMPATH\Honeypot\Honeypot.php on line 93. --- system/Honeypot/Honeypot.php | 4 ++++ tests/system/Honeypot/HoneypotTest.php | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/system/Honeypot/Honeypot.php b/system/Honeypot/Honeypot.php index 82da90020cac..7871a1925832 100644 --- a/system/Honeypot/Honeypot.php +++ b/system/Honeypot/Honeypot.php @@ -78,6 +78,10 @@ public function hasContent(RequestInterface $request) */ public function attachHoneypot(ResponseInterface $response) { + if ($response->getBody() === null) { + return; + } + if ($response->getCSP()->enabled()) { // Add id attribute to the container tag. $this->config->container = str_ireplace( diff --git a/tests/system/Honeypot/HoneypotTest.php b/tests/system/Honeypot/HoneypotTest.php index f3b4a659934f..0ed98e769f50 100644 --- a/tests/system/Honeypot/HoneypotTest.php +++ b/tests/system/Honeypot/HoneypotTest.php @@ -67,6 +67,15 @@ public function testAttachHoneypot(): void $this->assertStringNotContainsString($this->config->name, $this->response->getBody()); } + public function testAttachHoneypotBodyNull(): void + { + $this->response->setBody(null); + + $this->honeypot->attachHoneypot($this->response); + + $this->assertNull($this->response->getBody()); + } + public function testAttachHoneypotAndContainer(): void { $this->response->setBody('
');