Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/aotextarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,20 @@ void AOTextArea::addMessage(QString name, QString message, QString nameColor, QS
message += " ";
}

QString result = message.toHtmlEscaped().replace("\n", "<br>").replace(url_parser_regex, "<a href='\\1'>\\1</a>");
// Detect URLs before HTML escaping to prevent & from becoming &amp; in links
QString result;
int lastEnd = 0;
QRegularExpressionMatchIterator it = url_parser_regex.globalMatch(message);
while (it.hasNext())
{
QRegularExpressionMatch match = it.next();
result += message.mid(lastEnd, match.capturedStart() - lastEnd).toHtmlEscaped();
QString url = match.captured(1);
result += "<a href='" + url + "'>" + url.toHtmlEscaped() + "</a>";
lastEnd = match.capturedEnd();
}
result += message.mid(lastEnd).toHtmlEscaped();
result.replace("\n", "<br>");

if (!messageColor.isEmpty())
{
Expand Down
15 changes: 14 additions & 1 deletion src/lobby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,20 @@ void Lobby::set_server_description(const QString &server_description)
{
ui_server_description_text->clear();
static QRegularExpression regexp_links("\\b(https?://\\S+\\.\\S+)\\b");
QString result = server_description.toHtmlEscaped().replace("\n", "<br>").replace(regexp_links, "<a href='\\1'>\\1</a>");
// Detect URLs before HTML escaping to prevent & from becoming &amp; in links
QString result;
int lastEnd = 0;
QRegularExpressionMatchIterator it = regexp_links.globalMatch(server_description);
while (it.hasNext())
{
QRegularExpressionMatch match = it.next();
result += server_description.mid(lastEnd, match.capturedStart() - lastEnd).toHtmlEscaped();
QString url = match.captured(1);
result += "<a href='" + url + "'>" + url.toHtmlEscaped() + "</a>";
lastEnd = match.capturedEnd();
}
result += server_description.mid(lastEnd).toHtmlEscaped();
result.replace("\n", "<br>");
ui_server_description_text->insertHtml(result);
}

Expand Down