Skip to content

fix: Skip link check for empty message#12681

Open
kesselb wants to merge 1 commit intomainfrom
bug/skip-empty-message-link-check
Open

fix: Skip link check for empty message#12681
kesselb wants to merge 1 commit intomainfrom
bug/skip-empty-message-link-check

Conversation

@kesselb
Copy link
Copy Markdown
Contributor

@kesselb kesselb commented Mar 31, 2026

Fix #12674

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
@kesselb
Copy link
Copy Markdown
Contributor Author

kesselb commented Mar 31, 2026

/backport to stable5.7

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a Nextcloud Mail crash caused by passing an empty HTML string into DOMDocument::loadHTML() during phishing link checking (issue #12674) by short-circuiting link detection on empty messages.

Changes:

  • Add an early return in LinkCheck::run() when the HTML message is empty to avoid parsing.
  • Refactor result creation into a shared generateResult() helper.
  • Add a unit test to ensure empty messages do not trigger phishing detection (and do not crash).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/Service/PhishingDetection/LinkCheck.php Skips DOM parsing for empty input and consolidates result construction.
tests/Unit/Service/Phishing/LinkCheckTest.php Adds coverage to ensure empty HTML input is handled safely.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

$results = [];
$zippedArray = [];

if (empty($htmlMessage)) {
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty($htmlMessage) treats the string "0" as empty and will skip link checking in that (non-empty) case. Since the goal is to avoid calling the HTML parser on truly empty/blank content, consider using a stricter check like $htmlMessage === '' (or trim($htmlMessage) === '' if whitespace-only messages should also be skipped) to avoid surprising behavior.

Suggested change
if (empty($htmlMessage)) {
if (trim($htmlMessage) === '') {

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but 0 is not a valid url/link either ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mail app crash: DOMDocument::loadHTML() called with empty string in Parser.php (PhishingDetection)

2 participants