From 089c6c1a4651f91843ced368b2132bcdfa1ee35f Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Mon, 7 Nov 2022 16:34:33 +0100 Subject: [PATCH] Add validity checks for mentions before inserting them into the message For yet unknown reasons, sometimes invalid mentions are inserted into the list, which will mess up all further messages. While finding those bugs is the better approach, these checks should also be useful. --- src/actionshandler.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/actionshandler.cpp b/src/actionshandler.cpp index 3fd20bb91..50bbf3cb6 100644 --- a/src/actionshandler.cpp +++ b/src/actionshandler.cpp @@ -77,10 +77,14 @@ void ActionsHandler::handleMessage() }); for (const auto &mention : *m_room->mentions()) { + if (mention.text.isEmpty() || mention.id.isEmpty()) { + continue; + } handledText = handledText.replace(mention.cursor.anchor(), mention.cursor.position() - mention.cursor.anchor(), QStringLiteral("[%1](https://matrix.to/#/%2)").arg(mention.text, mention.id)); } + m_room->mentions()->clear(); if (NeoChatConfig::allowQuickEdit()) { QRegularExpression sed("^s/([^/]*)/([^/]*)(/g)?$");