[Chat] Fix percent-encoding and scheme gating in game-link chat labels

Game descriptions containing '%' were rendered as '%25' in the chat
button label because QUrlQuery's default decode leaves %25 untouched.
Use QUrl::FullyDecoded for the description item, and restrict the
invite-button treatment to cockatrice://joingame links; any other
cockatrice:// scheme now falls through to plain text.
This commit is contained in:
Lukas Brübach 2026-08-16 21:28:05 +02:00
parent 2076ac734d
commit 0fb4f4fa53

View file

@ -226,7 +226,9 @@ void ChatView::appendGameLinkTag(QTextCursor &cursor, const QString &url)
const QUrl gameUrl(url);
const QUrlQuery query(gameUrl);
const QString hostname = query.queryItemValue("hostname");
const QString description = query.queryItemValue("game");
// FullyDecoded undoes every %XX escape, so a description that itself
// contains "%" cannot end up displayed as "%25" in the label.
const QString description = query.queryItemValue("game", QUrl::FullyDecoded);
const int gameId = query.queryItemValue("gameid").toInt();
QString label;
@ -544,9 +546,14 @@ void ChatView::checkWord(QTextCursor &cursor, QString &message)
}
if (fullWordUpToSpaceOrEnd.startsWith("cockatrice://", Qt::CaseInsensitive)) {
appendGameLinkTag(cursor, fullWordUpToSpaceOrEnd);
cursor.insertText(rest, defaultFormat);
return;
// Only links to a game (cockatrice://joingame) become invite buttons;
// any other cockatrice:// scheme falls through to plain text below.
const QUrl gameLink(fullWordUpToSpaceOrEnd);
if (gameLink.host().compare("joingame", Qt::CaseInsensitive) == 0) {
appendGameLinkTag(cursor, fullWordUpToSpaceOrEnd);
cursor.insertText(rest, defaultFormat);
return;
}
}
// check word mentions