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('
');