diff --git a/autotests/texthandlertest.cpp b/autotests/texthandlertest.cpp index f2b5b6c29..da06d3415 100644 --- a/autotests/texthandlertest.cpp +++ b/autotests/texthandlertest.cpp @@ -46,6 +46,7 @@ private Q_SLOTS: void sendCustomEmojiCode_data(); void sendCustomEmojiCode(); + void receiveSpacelessSelfClosingTag(); void receiveStripReply(); void receivePlainTextIn(); @@ -252,6 +253,19 @@ void TextHandlerTest::sendCustomEmojiCode() QCOMPARE(testTextHandler.handleSendText(), testOutputString); } +void TextHandlerTest::receiveSpacelessSelfClosingTag() +{ + const QString testInputString = QStringLiteral("Test...
...ing"); + const QString testRichOutputString = QStringLiteral("Test...
...ing"); + const QString testPlainOutputString = QStringLiteral("Test...\n...ing"); + + TextHandler testTextHandler; + testTextHandler.setData(testInputString); + + QCOMPARE(testTextHandler.handleRecieveRichText(), testRichOutputString); + QCOMPARE(testTextHandler.handleRecievePlainText(Qt::RichText), testPlainOutputString); +} + void TextHandlerTest::receiveStripReply() { const QString testInputString = QStringLiteral( @@ -536,7 +550,7 @@ void TextHandlerTest::componentOutput_data() "someField }\nCustomQml {\n someTextProperty: someField.text\n}\nSure you can, it's still local to the same file where you " "defined the id") << QList{ - MessageComponent{MessageComponentType::Text, QStringLiteral("Ah, you mean something like"), {}}, + MessageComponent{MessageComponentType::Text, QStringLiteral("Ah, you mean something like
"), {}}, MessageComponent{ MessageComponentType::Code, QStringLiteral( diff --git a/src/texthandler.cpp b/src/texthandler.cpp index c3e02b4b4..5b45966b8 100644 --- a/src/texthandler.cpp +++ b/src/texthandler.cpp @@ -459,7 +459,7 @@ QString TextHandler::cleanAttributes(const QString &tag, const QString &tagStrin nextAttributeIndex += 1; while (nextAttributeIndex < tagString.length()) { - nextSpaceIndex = tagString.indexOf(TextRegex::endTagType, nextAttributeIndex); + nextSpaceIndex = tagString.indexOf(TextRegex::endAttributeType, nextAttributeIndex); if (nextSpaceIndex == -1) { nextSpaceIndex = tagString.length(); } @@ -505,7 +505,7 @@ QVariantMap TextHandler::getAttributes(const QString &tag, const QString &tagStr nextAttributeIndex += 1; while (nextAttributeIndex < tagString.length()) { - nextSpaceIndex = tagString.indexOf(TextRegex::endTagType, nextAttributeIndex); + nextSpaceIndex = tagString.indexOf(TextRegex::endAttributeType, nextAttributeIndex); if (nextSpaceIndex == -1) { nextSpaceIndex = tagString.length(); } diff --git a/src/utils.h b/src/utils.h index a0d688c26..7e284e2a9 100644 --- a/src/utils.h +++ b/src/utils.h @@ -57,7 +57,8 @@ inline QColor getUserColor(qreal hueF) namespace TextRegex { -static const QRegularExpression endTagType{QStringLiteral("(>| )")}; +static const QRegularExpression endTagType{QStringLiteral("[> /]")}; +static const QRegularExpression endAttributeType{QStringLiteral("[> ]")}; static const QRegularExpression attributeData{QStringLiteral("['\"](.*?)['\"]")}; static const QRegularExpression removeReply{QStringLiteral("> <.*?>.*?\\n\\n"), QRegularExpression::DotMatchesEverythingOption}; static const QRegularExpression removeRichReply{QStringLiteral(".*?"), QRegularExpression::DotMatchesEverythingOption};