Handle escaped html for plain text output

Always unescape html for plain text output no matter what the input is.
This commit is contained in:
James Graham
2023-04-09 14:20:22 +00:00
parent 7bb7dd7bbb
commit 4341cc437d
2 changed files with 17 additions and 9 deletions

View File

@@ -6,7 +6,7 @@
#include "texthandler.h" #include "texthandler.h"
#include <connection.h> #include <qnamespace.h>
#include <quotient_common.h> #include <quotient_common.h>
#include <syncdata.h> #include <syncdata.h>
@@ -49,7 +49,8 @@ private Q_SLOTS:
void receiveStripReply(); void receiveStripReply();
void receivePlainTextIn(); void receivePlainTextIn();
void recieveRichInPlainOut(); void receiveRichInPlainOut_data();
void receiveRichInPlainOut();
void receivePlainStripHtml(); void receivePlainStripHtml();
void receivePlainStripMarkup(); void receivePlainStripMarkup();
void receiveStripNewlines(); void receiveStripNewlines();
@@ -349,15 +350,24 @@ void TextHandlerTest::receiveStripReply()
QCOMPARE(testTextHandler.handleRecievePlainText(), testOutputString); QCOMPARE(testTextHandler.handleRecievePlainText(), testOutputString);
} }
void TextHandlerTest::recieveRichInPlainOut() void TextHandlerTest::receiveRichInPlainOut_data()
{ {
const QString testInputString = QStringLiteral("a &amp; b"); QTest::addColumn<QString>("testInputString");
const QString testOutputString = QStringLiteral("a & b"); QTest::addColumn<QString>("testOutputString");
QTest::newRow("ampersand") << QStringLiteral("a &amp; b") << QStringLiteral("a & b");
QTest::newRow("quote") << QStringLiteral("&quot;a and b&quot;") << QStringLiteral("\"a and b\"");
}
void TextHandlerTest::receiveRichInPlainOut()
{
QFETCH(QString, testInputString);
QFETCH(QString, testOutputString);
TextHandler testTextHandler; TextHandler testTextHandler;
testTextHandler.setData(testInputString); testTextHandler.setData(testInputString);
QCOMPARE(testTextHandler.handleRecievePlainText(), testOutputString); QCOMPARE(testTextHandler.handleRecievePlainText(Qt::RichText), testOutputString);
} }
void TextHandlerTest::receivePlainTextIn() void TextHandlerTest::receivePlainTextIn()

View File

@@ -235,9 +235,7 @@ QString TextHandler::handleRecievePlainText(Qt::TextFormat inputFormat, const bo
// Escaping then unescaping allows < and > to be maintained in a plain text string // Escaping then unescaping allows < and > to be maintained in a plain text string
// otherwise markdownToHTML will strip what it thinks is a bad html tag entirely. // otherwise markdownToHTML will strip what it thinks is a bad html tag entirely.
if (inputFormat == Qt::PlainText) { outputString = unescapeHtml(outputString);
outputString = unescapeHtml(outputString);
}
outputString = outputString.trimmed(); outputString = outputString.trimmed();
return outputString; return outputString;