Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log: properly escape all html except newlines #7783

Merged
merged 2 commits into from Mar 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions rpcs3/rpcs3qt/log_frame.cpp
Expand Up @@ -521,7 +521,11 @@ void log_frame::UpdateUI()
const auto font_start_tag = [](const QColor& color) -> const QString { return QStringLiteral("<font color = \"") % color.name() % QStringLiteral("\">"); };
const QString font_start_tag_stack = "<font color = \"" % m_color_stack.name() % "\">";
const QString font_end_tag = QStringLiteral("</font>");
const QString br_tag = QStringLiteral("<br/>");

static constexpr auto escaped = [](QString& text)
{
return text.toHtmlEscaped().replace(QStringLiteral("\n"), QStringLiteral("<br/>"));
};

// Check main logs
while (auto* packet = s_gui_listener.get())
Expand Down Expand Up @@ -570,21 +574,21 @@ void log_frame::UpdateUI()
{
text_cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
text_cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
text_cursor.insertHtml(font_start_tag(m_color[static_cast<int>(packet->sev)]) % text.replace("\n", br_tag) % font_start_tag_stack % QStringLiteral(" x") % QString::number(++m_log_counter) % font_end_tag % font_end_tag);
text_cursor.insertHtml(font_start_tag(m_color[static_cast<int>(packet->sev)]) % escaped(text) % font_start_tag_stack % QStringLiteral(" x") % QString::number(++m_log_counter) % font_end_tag % font_end_tag);
}
else
{
m_log_counter = 1;
m_old_log_text = text;

m_log->setTextCursor(text_cursor);
m_log->appendHtml(font_start_tag(m_color[static_cast<int>(packet->sev)]) % text.replace("\n", br_tag) % font_end_tag);
m_log->appendHtml(font_start_tag(m_color[static_cast<int>(packet->sev)]) % escaped(text) % font_end_tag);
}
}
else
{
m_log->setTextCursor(text_cursor);
m_log->appendHtml(font_start_tag(m_color[static_cast<int>(packet->sev)]) % text.replace("\n", br_tag) % font_end_tag);
m_log->appendHtml(font_start_tag(m_color[static_cast<int>(packet->sev)]) % escaped(text) % font_end_tag);
}

// if we mark text from right to left we need to swap sides (start is always smaller than end)
Expand Down