diff --git a/lib/Service/PhishingDetection/LinkCheck.php b/lib/Service/PhishingDetection/LinkCheck.php index 132127d41b..c9b270bdaa 100644 --- a/lib/Service/PhishingDetection/LinkCheck.php +++ b/lib/Service/PhishingDetection/LinkCheck.php @@ -74,6 +74,12 @@ public function run(string $htmlMessage) : PhishingDetectionResult { ]; } foreach ($zippedArray as $zipped) { + // Skip URLs that cannot be parsed to avoid deprecation errors in URL\Normalizer + // with malformed URLs in PHP 8.1+ + if (parse_url($zipped['href']) === false) { + continue; + } + $un = new Normalizer($zipped['href']); $url = $un->normalize(); if ($this->textLooksLikeALink($zipped['linkText'])) { diff --git a/tests/Unit/Service/PhishingDetection/LinkCheckTest.php b/tests/Unit/Service/PhishingDetection/LinkCheckTest.php index 85c1cb06e6..995abe9af7 100644 --- a/tests/Unit/Service/PhishingDetection/LinkCheckTest.php +++ b/tests/Unit/Service/PhishingDetection/LinkCheckTest.php @@ -87,4 +87,13 @@ public function testLinkWithQuotesReturnsSafe(): void { $this->assertFalse($result->isPhishing()); } + + public function testMalformedUrlReturnsSafe(): void { + // Test that malformed URLs don't cause errors but are silently skipped + $html = '
Click here'; + + $result = $this->check->run($html); + + $this->assertFalse($result->isPhishing()); + } }