messages display: fix the display of links

The links are now postprocessed to compensate for the malfunctions of
md4c. It now displays properly even with a + or - in it. It's also
checked by the unittests.

GitLab: #1903
Change-Id: I0d7f520a7a3fe06fb89107fe6b08f83325218cd4
This commit is contained in:
pmagnier-slimani
2025-02-14 14:35:06 -05:00
committed by Page Magnier-Slimani
parent 84ac5dba02
commit 65d3befad8
3 changed files with 71 additions and 0 deletions

View File

@@ -107,6 +107,41 @@ TEST_F(MessageParserFixture, ALinkIsParsedCorrectly)
// The rest of the link info is not tested here.
}
/*!
* WHEN We parse a text body with a link and a + or a -.
* THEN The HTML body should be returned correctly including the link even if MD4C doesn't detect it.
*/
TEST_F(MessageParserFixture, AComplexLinkIsParsedCorrectly)
{
auto linkColor = QColor::fromRgb(0, 0, 255);
auto backgroundColor = QColor::fromRgb(0, 0, 255);
QSignalSpy messageParsedSpy(globalEnv.messageParser.data(), &MessageParser::messageParsed);
QSignalSpy linkInfoReadySpy(globalEnv.messageParser.data(), &MessageParser::linkInfoReady);
// Parse a message with a link containing a + or a -.
globalEnv.messageParser->parseMessage("msgId_03",
"https://review.jami.net/q/status:open+-is:wip",
false,
linkColor,
backgroundColor);
// Wait for the messageParsed signal which should be emitted once.
messageParsedSpy.wait();
EXPECT_EQ(messageParsedSpy.count(), 1);
QList<QVariant> messageParserArguments = messageParsedSpy.takeFirst();
EXPECT_TRUE(messageParserArguments.at(0).typeId() == qMetaTypeId<QString>());
EXPECT_EQ(messageParserArguments.at(0).toString(), "msgId_03");
EXPECT_TRUE(messageParserArguments.at(1).typeId() == qMetaTypeId<QString>());
EXPECT_EQ(messageParserArguments.at(1).toString(),
"<style>a{color:#0000ff;}</style><p><a "
"href=\"https://review.jami.net/q/status:open+-is:wip\">https://review.jami.net/q/"
"status:open+-is:wip</a></p>\n");
// The rest of the link info is not tested here.
}
/*!
* WHEN We parse a text body with end of line characters.
* THEN The HTML body should be returned correctly with the end of line characters.