Skip to content

Commit

Permalink
fix: DEPRECATED error in Honeypot
Browse files Browse the repository at this point in the history
[DEPRECATED] str_ireplace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in SYSTEMPATH\Honeypot\Honeypot.php on line 93.
  • Loading branch information
kenjis committed Dec 9, 2023
1 parent ba8c285 commit 3f1a71b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions system/Honeypot/Honeypot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions tests/system/Honeypot/HoneypotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<form></form>');
Expand Down

0 comments on commit 3f1a71b

Please sign in to comment.