Skip to content

Commit 4c7db57

Browse files
committed
fix: Skip link check for empty message
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
1 parent b5537bd commit 4c7db57

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

lib/Service/PhishingDetection/LinkCheck.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ private function parse(string $url): string {
4949
}
5050

5151
public function run(string $htmlMessage) : PhishingDetectionResult {
52-
5352
$results = [];
5453
$zippedArray = [];
5554

55+
if (empty($htmlMessage)) {
56+
return $this->generateResult($results);
57+
}
58+
5659
$dom = Parser::parseToDomDocument($htmlMessage);
5760
$anchors = $dom->getElementsByTagName('a');
5861
foreach ($anchors as $anchor) {
@@ -85,11 +88,24 @@ public function run(string $htmlMessage) : PhishingDetectionResult {
8588
}
8689
}
8790
}
88-
if (count($results) > 0) {
89-
return new PhishingDetectionResult(PhishingDetectionResult::LINK_CHECK, true, $this->l10n->t('Some addresses in this message are not matching the link text'), $results);
91+
92+
return $this->generateResult($results);
93+
}
94+
95+
private function generateResult(array $results): PhishingDetectionResult {
96+
if ($results === []) {
97+
return new PhishingDetectionResult(
98+
PhishingDetectionResult::LINK_CHECK,
99+
false
100+
);
90101
}
91-
return new PhishingDetectionResult(PhishingDetectionResult::LINK_CHECK, false);
92102

103+
return new PhishingDetectionResult(
104+
PhishingDetectionResult::LINK_CHECK,
105+
true,
106+
$this->l10n->t('Some addresses in this message are not matching the link text'),
107+
$results
108+
);
93109
}
94110

95111
}

tests/Unit/Service/Phishing/LinkCheckTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,11 @@ public function testAddressCasing(): void {
9393
$result = $this->service->run($htmlMessage);
9494
$this->assertFalse($result->isPhishing());
9595
}
96+
97+
public function testEmptyMessage(): void {
98+
$htmlMessage = '';
99+
100+
$result = $this->service->run($htmlMessage);
101+
$this->assertFalse($result->isPhishing());
102+
}
96103
}

0 commit comments

Comments
 (0)