mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-30 17:40:47 +03:00
escape html before parsing commonmark
This commit is contained in:
parent
15c1cd5d66
commit
1659176c0d
1 changed files with 16 additions and 1 deletions
|
@ -324,10 +324,25 @@ utils::linkifyMessage(const QString &body)
|
|||
return doc;
|
||||
}
|
||||
|
||||
QByteArray escapeRawHtml(const QByteArray &data) {
|
||||
QByteArray buffer;
|
||||
const size_t length = data.size();
|
||||
buffer.reserve(length);
|
||||
for(size_t pos = 0; pos != length; ++pos) {
|
||||
switch(data.at(pos)) {
|
||||
case '&': buffer.append("&"); break;
|
||||
case '<': buffer.append("<"); break;
|
||||
case '>': buffer.append(">"); break;
|
||||
default: buffer.append(data.at(pos)); break;
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
QString
|
||||
utils::markdownToHtml(const QString &text)
|
||||
{
|
||||
const auto str = text.toUtf8();
|
||||
const auto str = escapeRawHtml(text.toUtf8());
|
||||
const char *tmp_buf =
|
||||
cmark_markdown_to_html(str.constData(), str.size(), CMARK_OPT_DEFAULT);
|
||||
|
||||
|
|
Loading…
Reference in a new issue